Hi guys!
Is there some alternative to time.sleep() to prevent suspending connection between front and back end? Is there a way to prevent changes in the UI while pausing?
Hi guys!
Is there some alternative to time.sleep() to prevent suspending connection between front and back end? Is there a way to prevent changes in the UI while pausing?
To work around this issue, you should avoid using blocking operations like time.sleep within the main thread of your Streamlit app. Instead, consider using Streamlit’s built-in mechanisms for handling delays and updates. For example, you can use st.spinner to display a spinner while a long-running process is taking place, or use widgets like buttons to trigger actions without blocking the main thread.Here’s an example of how you can use st.spinner:
import streamlit as st
import time
with st.spinner(“Processing…”):
# Perform your time-consuming task here, but don’t use time.sleep
# Simulate a task that takes time
time.sleep(5)
st.success(“Task completed!”)This approach keeps your Streamlit app responsive and ensures the connection between the front-end and back-end remains active.
Hi @sai_krishna1, thank you for the answer!
I’m creating a real-time monitoring system for a graph data acquisition module. For the most part, I’m using MUI. Every time I’m using the st.spinner, the entire MUI dashboard goes away, while the spinner is only visible. When the processes within st.spinner()
finish, the dashboard is visible again. I would like to avoid that.
The reason I’m using time delay is to avoid reaching quotas when requesting data from the server. However, reaching the quotas is inevitable, so a status code 429 is returned or some other status code, letting me know that the request was unsuccessful. In these cases, the logic is to enter a while loop, make a request every t
seconds, until the request is successful.
I’m looking for a way to implement this logic with MUI, without sacrificing the UI experience. The desired outcome would be to have a countdown, while the entire app is still responsive. However, I’m not sure it’s possible with streamlit.
The best solution I’ve found is this implementation but I’m facing the same issue, as with st.spinner()
; the entire dashboard goes away until the countdown is finished.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.