Improve "missing ReportContext" threading error
See original GitHub issueIf you create a thread from your Streamlit script, and call streamlit functions from within that thread, you need to attach a ReportContext
to it or else your st.foo()
calls won’t do anything, and you’ll get a warning message that looks something like this:
“Thread ‘Thread-7’: missing ReportContext”
We should improve the error message to tell the user how to fix this! (We may just want an FAQ entry that we can link to from the error message.)
(The fix is to use add_report_ctx
on the thread immediately after it’s created:)
from streamlit.ReportThread import add_report_ctx
thread = threading.Thread(target=...)
add_report_ctx(thread)
thread.start()
Related discussion: https://discuss.streamlit.io/t/how-to-run-a-subprocess-programs-using-thread-inside-streamlit/2440
(2022 edit: please see my comments here - this is an internal Streamlit API and has some major caveats. In particular, please do not call st.foo
commands from other threads - at least in production code that needs to be stable.)
Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.
If you’d like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:18 (2 by maintainers)
Top GitHub Comments
For anyone stumbling over this, it has been renamed to
streamlit.report_thread.add_report_ctx(thread)
.Also you can do