标签:col class imp foo time return task __new__ rlock
import threading import time class Foo: _instance = None _lock = threading.RLOCK() def __new__(cls,*args,**kwargs): if cls._instance: return cls._instance with cls._lock: if not cls._instance = object.__new__(cls) return cls._instance def task(): obj=Foo() print(obj) for i in range(10): t=threading.Thread(target=task) t.start()
标签:col class imp foo time return task __new__ rlock
原文地址:https://www.cnblogs.com/zxmbky/p/10218480.html