import threading
class ThreadSafeSingleton(type):
_instances= {}
_singleton_lock =threading.Lock()
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
with cls._singleton_lock:
if cls not in cls._instances:
cls._instances[cls] = super(ThreadSafeSingleton,cls).__call__(*args, **kwargs)
return cls._instances[cls]
class M2TWConfig(metaclass=ThreadSafeSingleton):
def __init__(self, *args, **kwargs):
pass
标签:__,args,python,kwargs,instances,单例,._,cls From: https://www.cnblogs.com/zhangjunrui/p/17113615.html