question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve "missing ReportContext" threading error

See original GitHub issue

If 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:open
  • Created 3 years ago
  • Reactions:3
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
tobycheesecommented, Dec 3, 2020

For anyone stumbling over this, it has been renamed to streamlit.report_thread.add_report_ctx(thread).

3reactions
royassiscommented, Aug 19, 2022

For version 1.12.0:

streamlit.runtime.scriptrunner import get_script_run_ctx

Also you can do

import streamlit as st
from threading import Thread
from streamlit.runtime.scriptrunner import add_script_run_ctx

def target():
    st.text("thread")

t = Thread(target=target)
add_script_run_ctx(t)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python use concurrent.futures in streamlit got "missing ...
A better solution would be to do any computation in the function, return the results and add the widgets etc. in the main...
Read more >
Concurrency with streamlit
Hey I want to run a code concurrently with streamlit, i'm trying to use threads, and I'm getting this error: 2022-08-19 08:09:33.852 Thread...
Read more >
Error in Birt report - OpenText Forums
I have migrated reports made in Birt 3.2 to 4.2, when I am trying to preview one of the reports it is giving...
Read more >
BIRT - how to properly configure Report Designer (for Maximo 7)
There is following problem during preview of the report: ... MXReportScriptContext.initialize(reportContext);"stack trace at java.lang.Thread.run(Unknown ...
Read more >
Robot Framework User Guide
This is a problem especially if keywords take a lot of arguments and/or arguments contain spaces. In such cases the pipe delimited variant...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found