Implemented a singleton using Method 1 from this question:
def singleton(class_):
instances = {}
def getinstance(*args, **kwargs):
if class_ not in instances:
instances[class_] = class_(*args, **kwargs)
return instances[class_]
return getinstance
@singleton
class MyClass(BaseClass):
pass
This works locally when I'm running it locally, but when I deploy it with gunicorn and django-crontabs it appears as if the singleton doesn't hold up and multiple instances of the class are instantiated. I'm wondering if each gunicorn worker spawns a separate instance of the class. In short, I'm asking about the interactions with Python and Django when running a web application with gunicorn.