Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InProcessKernelClient: Do not use run_sync if already in a running loop #1106

Closed
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