Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Make ReleaseSchedule singleton class thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
locriandev committed Oct 26, 2022
1 parent 3c20b2b commit 3f61afd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions doozerlib/release_schedule.py
@@ -1,5 +1,6 @@
from datetime import datetime
import os
import threading

import yaml

Expand All @@ -13,11 +14,16 @@ class ReleaseSchedule:
"""

_instance = None
_lock = threading.Lock()

def __new__(cls, runtime):
if cls._instance is None:
cls._instance = super(ReleaseSchedule, cls).__new__(cls)
cls.initialize(runtime)
with cls._lock:
# Another thread could have created the instance before the lock was acquired
# So check that the instance is still nonexistent.
if cls._instance is None:
cls._instance = super(ReleaseSchedule, cls).__new__(cls)
cls.initialize(runtime)
return cls._instance

@classmethod
Expand Down

0 comments on commit 3f61afd

Please sign in to comment.