Python: Delete Singleton Object Instance running Flask Application -
i have application global errorhandler object. object has metaclass singleton.
here singleton:
#!/usr/bin/python class singleton(type): def __init__(cls,name,bases,dic): super(singleton,cls).__init__(name,bases,dic) cls.instance=none def __call__(cls,*args,**kw): if cls.instance none: cls.instance=super(singleton,cls).__call__(*args,**kw) return cls.instance
here errorhandler:
#!/usr/bin/python # -*- encoding: utf-8 -*- singleton import singleton class errorhandler(object): __metaclass__ = singleton _errors = [] def __init__(self): self._jobid = "" def seterror(self , message ): self._errors.append( message ) def geterrors( self ): return self._errors def geterrorcount(self): return len(self._errors) def setjobid( self, jobid ): self._jobid = jobid def getjobid( self ): return self._jobid @classmethod def clear_instance(cls): del cls.instance def __del__(self): class_name = self.__class__.__name__ print class_name, "destroyed"
my problem is, not able kill instance on destructor. webservice should restful, errorhandler still exists on every request. maybe possible tell flask run every request inside own process. tried run flask app this:
app.run(host="0.0.0.0", debug=true, threaded=true)
but won't work solve problem. workaround set error list zero, isn't threadsafe.
hope recommendations. thank in advance
greetings jörn
Comments
Post a Comment