Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import threading
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def long_running_task():
|
| 7 |
+
time.sleep(5)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@st.cache_resource
|
| 11 |
+
def get_global_lock():
|
| 12 |
+
return threading.Lock()
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
global_lock = get_global_lock()
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
st.write("This is a long running task")
|
| 19 |
+
|
| 20 |
+
with st.spinner("Running long running task"):
|
| 21 |
+
with global_lock:
|
| 22 |
+
st.write("Task started")
|
| 23 |
+
long_running_task()
|
| 24 |
+
|
| 25 |
+
st.write("Task completed")
|