Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,24 +2,19 @@ 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.
|
19 |
-
|
20 |
-
with
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
st.write("Task completed")
|
|
|
2 |
import threading
|
3 |
import time
|
4 |
|
|
|
5 |
def long_running_task():
|
6 |
time.sleep(5)
|
7 |
|
|
|
8 |
@st.cache_resource
|
9 |
def get_global_lock():
|
10 |
return threading.Lock()
|
11 |
|
|
|
12 |
global_lock = get_global_lock()
|
13 |
|
14 |
+
# Add a button to start the task
|
15 |
+
if st.button('Start long running task'):
|
16 |
+
with st.spinner("Running long running task"):
|
17 |
+
with global_lock:
|
18 |
+
st.write("Task started")
|
19 |
+
long_running_task()
|
20 |
+
st.write("Task completed")
|
|
|
|