Skip to content

Commit db8d93d

Browse files
authored
fix: handle missing loop case outside except in run_sync (#437)
1 parent 83f1322 commit db8d93d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

jupyter_core/utils/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,15 @@ def run_sync(coro: Callable[..., Awaitable[T]]) -> Callable[..., T]:
150150
def wrapped(*args: Any, **kwargs: Any) -> Any:
151151
name = threading.current_thread().name
152152
inner = coro(*args, **kwargs)
153+
154+
loop_running = False
153155
try:
154156
asyncio.get_running_loop()
157+
loop_running = True
155158
except RuntimeError:
159+
pass
160+
161+
if not loop_running:
156162
# No loop running, run the loop for this thread.
157163
loop = ensure_event_loop()
158164
return loop.run_until_complete(inner)

0 commit comments

Comments
 (0)