Skip to content

Commit

Permalink
Fix st.spinner to use asyncio instead of threading to work on Pyodide
Browse files Browse the repository at this point in the history
  • Loading branch information
whitphx committed Mar 15, 2024
1 parent 15bb546 commit f7c9950
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/streamlit/elements/spinner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,7 +75,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
Expand Down

0 comments on commit f7c9950

Please sign in to comment.