单例模式:
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]
原文:http://3396002.blog.51cto.com/3386002/1945673