I have a multi-page app where the first page “Inputs” is used for setting various parameters, and navigating to the second page “Results” starts execution of a computationally expensive function that uses the parameters from the first page as inputs. I am experiencing a undesirable behavior where if the user decides to go back to the first page “Inputs” while the expensive function is still executing, the function does not stop to execute. Even using st.stop() or st.button() to trigger raise of an exception does not stop the function to continue executing.
Is there any way to force a function to stop executing?
I’m not sure exactly how you have your script set up, but if you are in the middle of a long computation with no Streamlit commands in the mix, you can get stuck waiting for that computation to finish before Streamlit can take its next step, even if that step is st.stop(). So depending on what you’re doing, you might be able to sprinkle in some trivial Streamlit commands so that Streamlit can check in and interrupt. Or you might be able to use threading to control that long process.
Can you provide a minimum working sample of how you call your expensive process and try to interrupt it?
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.