Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions gradio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
UserProvidedPath,
)
from gradio.exceptions import Error, InvalidPathError
from threading import current_thread

if TYPE_CHECKING: # Only import for type checking (is False at runtime).
from gradio.blocks import BlockContext, Blocks
Expand Down Expand Up @@ -113,8 +114,9 @@ def safe_get_stop_event() -> asyncio.Event:
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
if not hasattr(current_thread(), "_safe_event_loop"):
current_thread()._safe_event_loop = asyncio.new_event_loop()
asyncio.set_event_loop(current_thread()._safe_event_loop)
return asyncio.Event()


Expand Down