mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2025-12-15 13:44:39 +00:00
15 lines
298 B
Python
15 lines
298 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
|
|
|