Here's some code:
from flask import Flask, request
import time, threading
class MyServer(Flask):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.reset()
def reset(self):
self.string = "hello"
application = MyServer(__name__)
@application.route("/set")
def set():
application.string = request.args["string"]
threading.Timer(10, application.reset()).start()
return request.args["string"] + " stored for 10 seconds"
@application.route("/get")
def get():
return application.string
if __name__ == "__main__":
application.debug = True
application.run()
My expectation/goal is that if you visit the endpoint /set?string=foo
then for the next 10 seconds the app will return "foo" any time you visit /get
, and from then on it will return "hello" until you hit the /set
endpoint again.
Instead, if I hit /set?string=foo
and then immediately '/get', the app returns "hello" and I see "TypeError: 'NoneType' object is not callable" in the console. Can anyone help?