Download Brain/src/singletone.py from posix4e/brain: direct link, hf CLI and curl.
- Browser
- Download file 633 Bytes
-
https://huggingface.co/spaces/posix4e/brain/resolve/main/Brain/src/singletone.py
- Command line
-
hf download hf://spaces/posix4e/brain/Brain/src/singletone.py
-
curl -L -o singletone.py https://huggingface.co/spaces/posix4e/brain/resolve/main/Brain/src/singletone.py
633 Bytes
| """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] | |
| class AbstractSingleton(abc.ABC, metaclass=Singleton): | |
| """ | |
| Abstract singleton class for ensuring only one instance of a class. | |
| """ | |
| pass | |