diff --git a/lib/streamlit/elements/spinner.py b/lib/streamlit/elements/spinner.py index 5f27bb626c87a..28dd542206f36 100644 --- a/lib/streamlit/elements/spinner.py +++ b/lib/streamlit/elements/spinner.py @@ -14,12 +14,12 @@ from __future__ import annotations +import asyncio import contextlib import threading from typing import Iterator import streamlit as st -from streamlit.runtime.scriptrunner import add_script_run_ctx @contextlib.contextmanager @@ -63,7 +63,8 @@ def set_message(): spinner_proto.cache = _cache message._enqueue("spinner", spinner_proto) - add_script_run_ctx(threading.Timer(DELAY_SECS, set_message)).start() + # Stlite: Since threading does not work on Pyodide, we use asyncio instead. + asyncio.get_event_loop().call_later(DELAY_SECS, set_message) # Yield control back to the context. yield