-1

I added a threading object in my flask app to store some information about my user, but I don't know that how long will the data in the object exist (eg. the_data.a_timestamp)?

the_data=threading.local()

I think maybe it will be destroyed after the user shutdown the computer.

baduker
  • 19,152
  • 9
  • 33
  • 56

1 Answers1

0

The thread local storage will exist only as long as the thread exists. It will definitely not last beyond the lifetime of your Flask server process. Depending on how your application server is set up (e.g. using WSGI), thread local storage may not even last beyond the current request.

On the other hand, there is nothing in Flask that ties a user to a thread: more than one thread can handle requests for the same user, or more than one user can have their requests handled by the same thread.

If you want to have persistent user data, you'll need to store that outside the server, in a database of some kind.

Daniel Pryden
  • 59,486
  • 16
  • 97
  • 135