How do I make my streamlit webapp timeout after certain time of inactivity by user on Windows & Unix systems.
Expected behavior:
User opens the webapp, leaves the tab running with no activity for some time. Streamlit script should close (st.stop() maybe) after a certain amount of time.
Debug info
Streamlit version: 1.27.0
Python version: 3.7.6
Using Conda? PipEnv? PyEnv? Pex?
OS version: Windows 10
Browser version: Chrome 83.0.4103.116
Additional information
Since I couldnt find anything inbuilt related to this, i tried to find if i can timeout a function instead.
I found this stackoverflow thread which i thought could be useful.
Here, i found the 3rd highest answer by user “Russia Must Remove Putin”
His solution involved using a @exit_after decorator to timeout a function.
While this solution did work somewhat it isnt what i intended to do. When i used this decorater, instead of timing out that particular function which it wrapped around & stopping its execution. It stopped the whole Streamlit app running in my terminal.
I had to run the command “streamlit run my_file.py” to get it back up.
What i need is for the streamlit script to run the st.stop() command after certain minutes of inactivity by user.
So, I am making this script to serve as an Webapp for doing server related tasks like status checks, etc. I have made functions for each of my tasks & they work as intended.
After i have done my tasks( number of tasks & its order are not predefined), i click “Logout” button on my UI to stop the script & send me an summary of whatever i have done in this session( i achieve this my storing a string in session state). The summary is sent via mail from python. This thing works as expected on logout button click.
Now i want to add timeout functionality to this for a case where I (user) forgets to logout (stop it).
I want to add my timeout functionality to basically stop the session/ browser tab after some time of inactivity & send me the summary after stopping the session.
Checking user timout logic in a separate thread: if the user times out: pushing True to queue.Queue()
Define a parent decorator function (lets call it- “check_user_timeout”): that checks if queue is empty or not : and if its non-empty: then calls st.stop()
Thanks for the reply.
During our own discussion, we thought the same as you just told, about running streamlit on another thread & monitoring it from other one.
But we were not able to do it successfully due to my less experience in python.
I think your solution might work but i wont be able to test this as we have abandoned the user time out feature & mandated all users to logout manually without fail. We were time bound with this webapp & hence had to fallback on this.
Thanks again.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
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.
Performance cookies
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.
Functional cookies
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.
Targeting cookies
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.