2023-03-27 19:53:47 -05:00
|
|
|
# Python imports
|
|
|
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
|
|
|
|
|
|
# Application imports
|
|
|
|
|
|
|
|
|
|
|
2023-03-27 21:25:54 -05:00
|
|
|
|
2023-03-27 19:53:47 -05:00
|
|
|
class SingletonError(Exception):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Singleton:
|
2025-10-21 22:20:06 -05:00
|
|
|
_instance = None
|
2023-03-27 19:53:47 -05:00
|
|
|
|
|
|
|
|
def __new__(cls, *args, **kwargs):
|
2025-12-28 19:53:05 -06:00
|
|
|
if cls._instance is not None:
|
|
|
|
|
logger.debug(f"'{cls.__name__}' is a Singleton. Returning instance...")
|
|
|
|
|
return cls._instance
|
2023-03-27 19:53:47 -05:00
|
|
|
|
2025-10-21 22:20:06 -05:00
|
|
|
cls._instance = super(Singleton, cls).__new__(cls)
|
|
|
|
|
return cls._instance
|
2025-12-28 19:53:05 -06:00
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
if self._instance is not None:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
super(Singleton, self).__init__()
|