Force stopping execution function


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?

Debug info

  • Streamlit version: 1.27.0
  • Python version: 3.10.12
  • OS: Windows 11

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?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.