1
0
Fork 0

Merging upstream version 2.3~rc1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-16 12:53:58 +01:00
parent 972d2d9aa2
commit ca2ec6771a
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
37 changed files with 1946 additions and 407 deletions

View file

@ -21,3 +21,28 @@ class Singleton(type):
instance = super(Singleton, cls).__call__(*args, **kwargs)
cls._instances[cls] = instance
return cls._instances[cls]
def destroy(cls):
'''Delete a singleton instance.
This is to be invoked using the derived class Name.
For example:
class Child(Singleton):
pass
child1 = Child() # Instantiate singleton
child2 = Child() # Get a reference to the singleton
print(f'{child1 is child2}') # True
Child.destroy() # Delete the singleton
print(f'{child1 is child2}') # Still True because child1 and child2 still hold reference to the singleton
child1 = Child() # Instantiate a new singleton and assign to child1
print(f'{child1 is child2}') # False
'''
cls._instances.pop(cls, None)