Summary
I have created 2 buttons submit and cancel, on submit click, long process gets executed. I need to cancel the execution of the currently running long process on a cancel button click?
I have created 2 buttons submit and cancel, on submit click, long process gets executed. I need to cancel the execution of the currently running long process on a cancel button click?
Hi @Umang_Gupta
The st.rerun
method may be what you’re looking for. Here’s the Docs page on this:
Hey @dataprofessor , Thanks for the reply.
I have tried with st.rerun as well, but still no luck.
Hi @Umang_Gupta
Can you look into using Session state where the buttons could reset the necessary session state variables so as to start fresh.
This is a quick example of how to so something similar using callback functions and session state. Please let me know if this helps.
import streamlit as st
import time
if "trigger_execution" not in st.session_state:
st.session_state["trigger_execution"] = False
def stop_processing():
st.session_state.clear()
def start_processing():
st.button("Cancel Execution", on_click=stop_processing)
st.session_state["trigger_execution"] = True
st.button("Start", on_click=start_processing)
if st.session_state["trigger_execution"]:
with st.spinner("Processing..."):
time.sleep(100)
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
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.
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.
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.
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.