Changing session state not reflecting in active python thread

Hey @JAGD,

I wanted to share some notes by @tim on multithreading from this related GitHub Issue:

None of Streamlit’s APIs are safe to call from any thread other than your script’s main thread; code that does so has ventured into the realm of undefined behavior, and we strongly recommend against it :slight_smile:

If you need to run a separate thread that invokes Streamlit APIs, you’ll need to do something like pushing requests to a shared queue that’s processed by your script thread.

(This isn’t something that’s particularly easy to do with Streamlit, unfortunately. But we do have some - still vague - plans to make more complex use cases, like this one, less tricky!)

Based on the above, it seems like what you’re seeing is unfortunately expected behavior. Agreed that we should document this more publicly for reference.