How to stop script execution without streamlit showing a traceback

Hi, I would like my script to stop execution if a condition is met, something like this

if BOOL_CONDITION:
    st.write("The condition was met, stopping execution here")
    sys.exit()

However, the streamlit always shows a red traceback like this

What I really don’t want to do, is to have an if-else structure, where 90% of my application gets an additional level of indentation :slight_smile:

Any help will be hugely appreciated, thanks!

Hello @ddzlob, welcome to the community!

I believe Streamlit now has st.stop :slight_smile: would that do the trick ?

if BOOL_CONDITION:
    st.write("The condition was met, stopping execution here")
    st.stop()

Cheers,
Fanilo

2 Likes

Oh yeeees, that’s exactly what I was looking for :slight_smile:

Thanks for taking the time to implement!

1 Like