python 单例
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