arnaudmiribel / streamlit-extras

Discover, try, install and share Streamlit re-usable bits we call "extras"!
https://extras.streamlit.app
Apache License 2.0
669 stars 117 forks source link

Add concurrency_limiter #223

Closed kajarenc closed 2 months ago

kajarenc commented 3 months ago

A concurrency limiter decorator could be used to limit the concurrent execution of functions. Could be useful for heavy computation/memory tasks, or when a task to requests to API with rate limits.

@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")
netlify[bot] commented 3 months ago

Deploy Preview for phenomenal-crepe-0effec ready!

Name Link
Latest commit 8d23420b323c14c947bc15e633bbb6285a5aea84
Latest deploy log https://app.netlify.com/sites/phenomenal-crepe-0effec/deploys/6629148b298fe400081ddca2
Deploy Preview https://deploy-preview-223--phenomenal-crepe-0effec.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.