How do I store something created by a thread, in a session, so I can access that value later in another request?
Here is a sample:
@app.route('/one')
def one():
@copy_current_request_context
def x():
session['status'] = "done"
t = threading.Thread(target=x)
t.start()
return "One"
@app.route('/two')
def two():
status = session['status']
return "Two: {}".format(status)
In example above I store the 'status' from within the thread (I need to run the thread) inside the /one request but later, let's say 5s, I want to check for the status in another request (/two).
Also does @copy_current_request_context make a read-only (or read and discard write) copy of the session/request?
question from:
https://stackoverflow.com/questions/66064183/how-to-share-session-values-created-outside-the-context-in-flask 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…