Merge pull request #1884 from thsrite/main
This commit is contained in:
commit
45b044cd6b
@ -1,4 +1,5 @@
|
|||||||
import abc
|
import abc
|
||||||
|
import threading
|
||||||
|
|
||||||
|
|
||||||
class Singleton(abc.ABCMeta, type):
|
class Singleton(abc.ABCMeta, type):
|
||||||
@ -7,9 +8,11 @@ class Singleton(abc.ABCMeta, type):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
_instances: dict = {}
|
_instances: dict = {}
|
||||||
|
_lock = threading.Lock()
|
||||||
|
|
||||||
def __call__(cls, *args, **kwargs):
|
def __call__(cls, *args, **kwargs):
|
||||||
key = (cls, args, frozenset(kwargs.items()))
|
key = (cls, args, frozenset(kwargs.items()))
|
||||||
|
with cls._lock:
|
||||||
if key not in cls._instances:
|
if key not in cls._instances:
|
||||||
cls._instances[key] = super().__call__(*args, **kwargs)
|
cls._instances[key] = super().__call__(*args, **kwargs)
|
||||||
return cls._instances[key]
|
return cls._instances[key]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user