ayaka.utils
def
singleton(cls):
2def singleton(cls): 3 '''单例模式的装饰器''' 4 instance = None 5 6 def getinstance(*args, **kwargs): 7 nonlocal instance 8 if instance is None: 9 instance = cls(*args, **kwargs) 10 return instance 11 12 return getinstance
单例模式的装饰器