2023-03-28 00:53:47 +00:00
|
|
|
# Python imports
|
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
|
|
|
|
# Application imports
|
|
|
|
|
|
|
|
|
2023-03-28 02:25:54 +00:00
|
|
|
|
2023-03-28 00:53:47 +00:00
|
|
|
class SingletonError(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Singleton:
|
|
|
|
ccount = 0
|
|
|
|
|
|
|
|
def __new__(cls, *args, **kwargs):
|
|
|
|
obj = super(Singleton, cls).__new__(cls)
|
|
|
|
cls.ccount += 1
|
|
|
|
|
|
|
|
if cls.ccount == 2:
|
|
|
|
raise SingletonError(f"Exceeded {cls.__name__} instantiation limit...")
|
|
|
|
|
|
|
|
return obj
|