mower-ng/mower/utils/singleton.py

10 lines
232 B
Python

# 单例模式
def singleton(cls):
instances = {}
def get_instance(*args, **kwargs):
if cls not in instances:
instances[cls] = cls(*args, **kwargs)
return instances[cls]
return get_instance