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.