Skip to content
Closed
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
9 changes: 8 additions & 1 deletion ipykernel/inprocess/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
# -----------------------------------------------------------------------------


def in_running_loop() -> bool:
try:
return asyncio.get_running_loop() is not None
except RuntimeError:
return False


class InProcessKernelClient(KernelClient):
"""A client for an in-process kernel.

Expand Down Expand Up @@ -189,7 +196,7 @@ def _dispatch_to_kernel(self, msg):
stream = kernel.shell_stream
self.session.send(stream, msg)
msg_parts = stream.recv_multipart()
if run_sync is not None:
if not in_running_loop() and run_sync is not None:
dispatch_shell = run_sync(kernel.dispatch_shell)
dispatch_shell(msg_parts)
else:
Expand Down