import streamlit as st import threading import time def long_running_task(): time.sleep(15) @st.cache_resource def get_global_lock(): return threading.Lock() global_lock = get_global_lock() # Add a button to start the task if st.button('Start long running task'): with global_lock: with st.spinner("Running long running task"): st.write("Task started") long_running_task() st.write("Task completed")