Add Ping's enhanced singleton decorator.
This commit is contained in:
parent
5d8316d6de
commit
e675128566
|
@ -270,7 +270,12 @@ some examples of use.
|
|||
::
|
||||
|
||||
def singleton(cls):
|
||||
return cls()
|
||||
instances = {}
|
||||
def getinstance():
|
||||
if cls not in instances:
|
||||
instances[cls] = cls()
|
||||
return instances[cls]
|
||||
return getinstance
|
||||
|
||||
class MyClass [singleton]:
|
||||
...
|
||||
|
|
Loading…
Reference in New Issue