π¦Β Β Concurrency limiter for your Streamlit app
Submitted by Karen Javadyan
Summary
This decorator limit function execution concurrency with max_concurrency param.
Functions
concurrency_limiter
Decorator that limits function concurrent execution in Stremalit app.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_concurrency |
int
|
The number of allowed instances of the decorated function to be run simultaneously Defaults to 1. |
1
|
show_spinner |
bool
|
If True, a spinner will be shown while waiting for the function to be executed. |
True
|
Source code in src/streamlit_extras/concurrency_limiter/__init__.py
Import:
- You should add this to the top of your .py file
Examples
example
def example():
@concurrency_limiter(max_concurrency=1)
def heavy_computation():
st.write("Heavy computation")
progress_text = "Operation in progress. Please wait."
my_bar = st.progress(0, text=progress_text)
for percent_complete in range(100):
time.sleep(0.15)
my_bar.progress(percent_complete + 1, text=progress_text)
st.write("END OF Heavy computation")
return 42
my_button = st.button("Run heavy computation")
if my_button:
heavy_computation()