mirror of
https://gitee.com/qpy-solutions/tracker-v2.git
synced 2025-05-18 18:48:25 +08:00
20 lines
533 B
Python
20 lines
533 B
Python
import _thread
|
|
|
|
|
|
class Singleton(object):
|
|
_instance_lock = _thread.allocate_lock()
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
pass
|
|
|
|
def __new__(cls, *args, **kwargs):
|
|
if not hasattr(cls, 'instance_dict'):
|
|
Singleton.instance_dict = {}
|
|
|
|
if str(cls) not in Singleton.instance_dict.keys():
|
|
with Singleton._instance_lock:
|
|
_instance = super().__new__(cls)
|
|
Singleton.instance_dict[str(cls)] = _instance
|
|
|
|
return Singleton.instance_dict[str(cls)]
|