How to catch if "Stop" built-in button was pressed OR work with st.progress widget


how to catch if “Stop” built-in button was pressed? I can’t use st.session_state for that. Or maybe another way for the solution how to hide st.success(“Processing”) if the “Start” button was pressed and then BUILT-IN “Stop” button was pressed before code was fully processed.

Steps to reproduce

Code snippet:
1 example:

import streamlit as st
import time

variable = st.empty()

if st.button("Start"):
    with variable.container():

#If someone pressed "Stop" built-in button:
#    variable.empty()

2 variant, after pressing “Stop” button spinner also works.

import streamlit as st
import time

if st.button("Start"):
    with st.spinner('Processing'):

I guess the st.progress() is okay to use, cause it’s works, but in this case can you please write how to increase st.progress value by 1 when we processed 100 values, for example, not only 1. Here is the code

import streamlit as st
import time

my_bar = st.progress(0)
sample = st.empty()

if "percent_complete" not in st.session_state:
    st.session_state.percent_complete = 0

values = 9122
max_value = 100

step = values // max_value

if st.button("Start"):
    for _, percent_complete in enumerate(range(max_value), 1):
        if _ % step == 0: # How to add 1 to percent_complete only after "step" values was processed
            my_bar.progress(percent_complete + 1)

        if percent_complete < max_value - 1:
            with sample.container():

In this code we using st.progress and until it’s not finished we show st.warning (изменено)

Expected behavior:

Explain what you expect to happen when you run the code above.

When we pressed “Stop” built-in button after “Start” button was pressed before code was processed hide st.success(“Processing”) (1 variant) OR stop spinner (2 variant) OR just write please how to increase st.progress by 1 when we processed “step” values, not only 1.

Debug info

  • Streamlit version: 1.14.0
  • Python version: 3.8
  • OS version: Windows 10

Additional information

Please write how to do ONLY for 1 of variants.