mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2025-12-17 04:51:10 +00:00
Initial commit
This commit is contained in:
14
unilabos/utils/decorator.py
Normal file
14
unilabos/utils/decorator.py
Normal file
@@ -0,0 +1,14 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user