Live plot from a thread

I did it like above, but I can’t found the “thread_safe_st” module.
So I try to get the ReportContext from main thread, and set it into the sub thread.
Lastly, I solved it, too.

# in main thread
KEY_CONTEXT = streamlit.ReportThread.REPORT_CONTEXT_ATTR_NAME
main_context = getattr(current_thread(), KEY_CONTEXT)

# in sub thread
thread = current_thread()
if getattr(thread, KEY_CONTEXT, None) is None:
    setattr(thread, KEY_CONTEXT, main_context)
# here, I can use st normally
st.success('Connect successfully.')
2 Likes