When a streamlit script is running, the user can click on the “Stop” button left of the menu hamburger, or press ctrl-c to stop streamlit altogether. I would like to run some code when this happens, in order to do some clean up before streamlit stops. Is there a way to do that please?
I am implementing something using asyncio per this thread, and when the user stops the processing, my asyncio thread is left hanging.
The best I can think of is to create a button or instructions at the top to click to either lure the user away from using the stop from the menu or instructing them how to properly refresh if they did click Stop.
Here is a thread about hiding that menu (by also hiding the header where the Running and Stop messages post, effectively taking the option away (though a user could circumvent it). Here’s the quick answer, but there are other solutions in the thread: How do i hide/ remove the menu in production? - #22 by snehankekre
You may be interested in GitHub Feature requests to customize that menu or hide it simply by command:
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.