Streamlit, asyncio and debugging in VS-code problem

Dear all,

I’d like to use async routines in my app and tested a little bit using vscode for debugging (see How to use Streamlit with VS Code? - #7 by w-markus). Already with this script

import streamlit as st 
import asyncio
from datetime import datetime

st.set_page_config(layout="wide")

st.markdown(
    """
    <style>
    .time {
        font-size: 130px !important;
        font-weight: 700 !important;
        color: #ec5953 !important;
    }
    </style>
    """,
    unsafe_allow_html=True
)

async def watch(test):
    while True:
        test.markdown(
            f"""
            <p class="time">
                {str(datetime.now())}
            </p>
            """, unsafe_allow_html=True)
        res = await asyncio.sleep(1)

test = st.empty()

if st.button("Click me."):
    st.image("https://cdn11.bigcommerce.com/s-7va6f0fjxr/images/stencil/1280x1280/products/40655/56894/Jdm-Decals-Like-A-Boss-Meme-Jdm-Decal-Sticker-Vinyl-Decal-Sticker__31547.1506197439.jpg?c=2", width=200)

asyncio.run(watch(test))

which actually originates from Issue with asyncio run in streamlit, I got stuck.

The script starts without problems, however, when clicking ‘Click me’ I receive

Exception has occurred: RerunException       (note: full exception trace is shown but execution is paused at: watch)
RerunData(query_string='', widget_states=widgets {
  id: "$$GENERATED_WIDGET_KEY-d1af2ca94fbc523761576e0810c8012c-None"
  trigger_value: true
}
)
  File "/home/markus/Software/Python/streamlit/test1.py", line 28, in watch (Current frame)
    test.markdown(
  File "/home/markus/Software/Python/streamlit/test1.py", line 42, in <module>
    asyncio.run(watch(test))

in the line test.markdown.

Unfortunately, I have no clue, why this is happening, though it seems, that doing this in PyCharm does not run into this problem (I’d like to stay with VS Code).

Thanks a lot in advance for every hint!
Markus

Dear all!

I think I found the root cause: in the side menu of vscode, one can tick mark whether execution is stopped and the editor is focused to the respective line of code upon certain exceptions:
image

Make sure, that “Uncaught Exceptions” is not marked, otherwise- I reckon - the RerunException issued by streamlit will be caught and lead to the breaks I have described above.

Happy scripting!

Markus