单例模式:
class sign_mode(object):
objs = {}
obj_last = threading.Lock()
def __new__(cls, *args, **kwargs):
if cls in cls.objs:
return cls.objs[cls]
cls.obj_last.acquire()
try:
cls.objs[cls] = super(sign_mode, cls).__new__(cls, *args, **kwargs)
finally:
cls.obj_last.release()
return cls.objs[cls]
转载于:https://blog.51cto.com/3396002/1945673