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-10-21 22:20:06 -05:00
|
|
|
if cls._instance:
|
|
|
|
|
raise SingletonError(f"'{cls.__name__}' is a Singleton. Cannot create a new 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
|