summaryrefslogtreecommitdiffstats
path: root/staslib/singleton.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-16 11:03:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-16 11:03:18 +0000
commit347467d3fa6fb239f917c05c4cf7f6c3fe7f9b30 (patch)
tree44ae9f59984c8a36b93f29a729f10473653f9f19 /staslib/singleton.py
parentAdding upstream version 2.2.2. (diff)
downloadnvme-stas-347467d3fa6fb239f917c05c4cf7f6c3fe7f9b30.tar.xz
nvme-stas-347467d3fa6fb239f917c05c4cf7f6c3fe7f9b30.zip
Adding upstream version 2.3~rc1.upstream/2.3_rc1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'staslib/singleton.py')
-rw-r--r--staslib/singleton.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/staslib/singleton.py b/staslib/singleton.py
index 2171186..f80fc0b 100644
--- a/staslib/singleton.py
+++ b/staslib/singleton.py
@@ -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)