aboutsummaryrefslogtreecommitdiff
path: root/autogpts/autogpt/autogpt/utils/singleton.py
blob: 46c6256e08725206d3e9a591245a24f90a653e6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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]