Skip to content

Update settings.py #654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/aleph/settings.py
Original file line number Diff line number Diff line change
@@ -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()