Button time.sleep freeze software

I use streamlit with infinite loop for taking data.
before loop I created button.
button have long waiting time inside
after button finish work it should compare actual data with data on start.
problem my algorithm have memory about data before pressing button, but not current.

which options I have?
It look like need multithreading or something similar?
because button freese streamlit on time of work
or is here other ways?

Streamlit 1.25 and Python 3.11

Hi @alma

It may be helpful to share a code snippet so that others in the community could get a better idea on the specifics of the implementation that you have in mind.

below approximate example.
need press button before value is 100.

my real data was changed in time of button execution, same like in this script
I would like to see

but now I have

import streamlit as st
import time

if "is_initialized" not in st.session_state or False:
    st.session_state.current_value = 0
    st.session_state.LIMIT = 20
    st.session_state.is_initialized = True

# need press button before current value more than 100
if st.sidebar.button("button"):
    st.write(st.session_state.current_value < st.session_state.LIMIT)
    st.write(st.session_state.current_value < st.session_state.LIMIT)

with st.empty():
    while True:


        st.session_state.current_value += 1