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?

local
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
True
False

but now I have
True
True
upd:

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)
    time.sleep(8)
    st.write(st.session_state.current_value < st.session_state.LIMIT)

with st.empty():
    while True:

        st.write(st.session_state.current_value)
        time.sleep(0.01)

        st.session_state.current_value += 1