Added Singleton class to inherit as needed

This commit is contained in:
2023-03-27 19:53:47 -05:00
parent 48d6c505a7
commit ef03030c88
6 changed files with 33 additions and 9 deletions

23
src/utils/singleton.py Normal file
View File

@@ -0,0 +1,23 @@
# Python imports
# Lib imports
# Application imports
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