aboutsummaryrefslogtreecommitdiff
path: root/autogpts/autogpt/autogpt/singleton.py
diff options
context:
space:
mode:
Diffstat (limited to 'autogpts/autogpt/autogpt/singleton.py')
-rw-r--r--autogpts/autogpt/autogpt/singleton.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/autogpts/autogpt/autogpt/singleton.py b/autogpts/autogpt/autogpt/singleton.py
new file mode 100644
index 000000000..46c6256e0
--- /dev/null
+++ b/autogpts/autogpt/autogpt/singleton.py
@@ -0,0 +1,16 @@
+"""The singleton metaclass for ensuring only one instance of a class."""
+import abc
+
+
+class Singleton(abc.ABCMeta, type):
+ """
+ Singleton metaclass for ensuring only one instance of a class.
+ """
+
+ _instances = {}
+
+ def __call__(cls, *args, **kwargs):
+ """Call method for the singleton metaclass."""
+ if cls not in cls._instances:
+ cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
+ return cls._instances[cls]