Is it possible to start streamlit server programmatically?

Hi,
I’m using streamlit to visualize information when something went wrong in my scripts. The program finishes normally most of the time. So I don’t want the streamlit server starts at the begining. It’s there a way to achieve this?
Thanks in advance.

try:
    img = load_image(image_path)
    processed_img = process_image(img)
except:
    st.code(this_function)
    st.image(img)