mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2026-01-17 11:40:39 +03:00
logger refactor
This commit is contained in:
18
app/utils/singleton.py
Normal file
18
app/utils/singleton.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from threading import Lock
|
||||
|
||||
|
||||
class SingletonMeta(type):
|
||||
"""
|
||||
This is a thread-safe implementation of Singleton.
|
||||
"""
|
||||
|
||||
_instances = {}
|
||||
|
||||
_lock: Lock = Lock()
|
||||
|
||||
def __call__(cls, *args, **kwargs):
|
||||
with cls._lock:
|
||||
if cls not in cls._instances:
|
||||
instance = super().__call__(*args, **kwargs)
|
||||
cls._instances[cls] = instance
|
||||
return cls._instances[cls]
|
||||
Reference in New Issue
Block a user