I'm trying to write to a global object from a flask request. I know that it's not recommended to use global variables in such scenario but I'm changing a state to perform some tests. I don't want to use any cache-memory solution such as pickledb.
I tried multiple approaches but none of them succeeded. Also I am trying to understand why the singleton solution does not work, eg
class Singleton:
foo = 'bar'
...
@app.RestApi.service.route('/test/endpoint1')
def endpoint1():
singleton_instance = Singleton.get_instance()
singleton_instance.foo='not bar'
print("Endpoint1 was called.")
At some point I call endpoint1: s = Singleton.get_instance() s.foo='bar'
#CALL ENDPOINT1 HERE USING URLLIB ....
time.sleep(10) #enough time to sync !!
And now if i get s.foo it won't be 'not bar'. instead it will not have changed !
Any idea why ??
Thank you