diff --git a/src/aleph/settings.py b/src/aleph/settings.py index a24a8ea16..bf868e34d 100644 --- a/src/aleph/settings.py +++ b/src/aleph/settings.py @@ -1,10 +1,27 @@ -from dataclasses import dataclass +from dataclasses import dataclass, field +from threading import Lock -@dataclass(frozen=True, eq=True) +@dataclass(frozen=True) class Settings: - use_executors: bool = True + """Immutable configuration settings.""" + use_executors: bool = field(default=True) + _instance = None # Private class-level variable for Singleton instance + _lock = Lock() # Lock to ensure thread-safe initialization -# Singleton -settings = Settings() + @classmethod + def instance(cls): + """ + Get the Singleton instance of the Settings class. + Ensures only one instance is created even in multithreaded environments. + """ + if cls._instance is None: + with cls._lock: # Double-checked locking + if cls._instance is None: + cls._instance = cls() # Initialize the Singleton instance + return cls._instance + + +# Access the Singleton instance +settings = Settings.instance()