def singleton(cls, *args, **kw):
instances = {}
def _singleton():
key = str(cls) + str(os.getpid())
if key not in instances:
instances[key] = cls(*args, **kw)
return instances[key]
return _singleton
@singleton
class mytest:
def __init__(self):
self.a='1'
python 单例模式实现
最新推荐文章于 2025-12-25 14:57:52 发布
1338

被折叠的 条评论
为什么被折叠?



