When the python script completes the job, I am getting a message in terminal âThread âThread-7â: missing ReportContextâ. This same piece of code worked in Jupyter widgets.
Can someone advise me what is the right way to use subprocess and threads in streamlit using above example?
Yeah, this isnât well-documented in Streamlit. If you want to perform Streamlit calls from within threads you create, you need to attach a Streamlit âReportContextâ to those threads. (This is a bit of state that lets Streamlit know which user session the thread belongs to.)
Hereâs how to attach a ReportContext to your thread. You should do this after creating the thread, and before starting it.
from streamlit.ReportThread import add_report_ctx
# Your thread creation code:
thread = threading.Thread(target=runInThread, args=(onExit, PopenArgs))
add_report_ctx(thread)
thread.start()
Iâve opened a feature request to improve the error message!
Thanks @tim, now my code runs without any error.
If you donât mind can you let me know how to return to streamlit once the subprocess gets done. For instance, in my previous post you can notice onExit(). Basically, what I was expecting is once the subprocess script is done, will print a message in streamlit app that the program finished running. But currently am not getting it.