Using streamlit with multithreading

I’ve seen a lot of threads regarding using streamlit with multithreading
I’ve tried everything that I’ve seen
But nothing seems to work as expected

The latest threads suggest using add_script_run_ctx (which for some reason looks different in every version of streamlit), but it doesn’t seem to work for me

It seems like adding simple objects like subheader kind of work
But adding things like columns and metric does not

Using streamlit 1.10

One possible code I’ve tried

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

stSystemStatsPlaceHolder = None

def update_system_stats():
        global stSystemStatsPlaceHolder
        with stSystemStatsPlaceHolder:    
              col1, col2, col3, col4, col5 = st.columns(5)

              col1.metric("Memory", '1')
              col2.metric("Swap", '2')
              col3.metric("CPU", '3')
              col4.metric("CPU Temp", '4')
              col5 .metric("GPU Temp", '5')


stSystemStatsPlaceHolder = st.empty()

thread = threading.Thread(target=update_system_stats)
add_script_run_ctx(thread)
thread.start()

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.