From 0c7aca07d45ff009327599f6985c6a8ebbd98987 Mon Sep 17 00:00:00 2001
From: David Brochart <david.brochart@gmail.com>
Date: Tue, 1 Jun 2021 09:41:11 +0200
Subject: [PATCH] Wrap jupyter_client's async functions with run_sync
---
.github/workflows/python-package.yml | 1 +
jupyter_console/ptshell.py | 16 +++++++++-------
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml
index eb8048e..fd5fcd0 100644
--- a/.github/workflows/python-package.yml
+++ b/.github/workflows/python-package.yml
@@ -29,6 +29,7 @@ jobs:
pip install pytest pytest-cov
pip install .
python -m ipykernel.kernelspec --user
+ pip install https://github.com/jupyter/jupyter_client/archive/master.zip
- name: Test with pytest
run: |
pytest --cov jupyter_console
diff --git a/jupyter_console/ptshell.py b/jupyter_console/ptshell.py
index a9daeed..d6dc1e7 100644
--- a/jupyter_console/ptshell.py
+++ b/jupyter_console/ptshell.py
@@ -76,6 +76,8 @@
from pygments.util import ClassNotFound
from pygments.token import Token
+from jupyter_client.utils import run_sync
+
def ask_yes_no(prompt, default=None, interrupt=None):
"""Asks a question and returns a boolean (y/n) answer.
@@ -705,8 +707,8 @@ def run_cell(self, cell, store_history=True):
return
# flush stale replies, which could have been ignored, due to missed heartbeats
- while self.client.shell_channel.msg_ready():
- self.client.shell_channel.get_msg()
+ while run_sync(self.client.shell_channel.msg_ready)():
+ run_sync(self.client.shell_channel.get_msg)()
# execute takes 'hidden', which is the inverse of store_hist
msg_id = self.client.execute(cell, not store_history)
@@ -739,7 +741,7 @@ def run_cell(self, cell, store_history=True):
#-----------------
def handle_execute_reply(self, msg_id, timeout=None):
- msg = self.client.shell_channel.get_msg(block=False, timeout=timeout)
+ msg = run_sync(self.client.shell_channel.get_msg)(block=False, timeout=timeout)
if msg["parent_header"].get("msg_id", None) == msg_id:
self.handle_iopub(msg_id)
@@ -778,7 +780,7 @@ def handle_is_complete_reply(self, msg_id, timeout=None):
## Get the is_complete response:
msg = None
try:
- msg = self.client.shell_channel.get_msg(block=True, timeout=timeout)
+ msg = run_sync(self.client.shell_channel.get_msg)(block=True, timeout=timeout)
except Empty:
warn('The kernel did not respond to an is_complete_request. '
'Setting `use_kernel_is_complete` to False.')
@@ -849,8 +851,8 @@ def handle_iopub(self, msg_id=''):
It only displays output that is caused by this session.
"""
- while self.client.iopub_channel.msg_ready():
- sub_msg = self.client.iopub_channel.get_msg()
+ while run_sync(self.client.iopub_channel.msg_ready)():
+ sub_msg = run_sync(self.client.iopub_channel.get_msg)()
msg_type = sub_msg['header']['msg_type']
# Update execution_count in case it changed in another session
@@ -1003,7 +1005,7 @@ def handle_image_callable(self, data, mime):
def handle_input_request(self, msg_id, timeout=0.1):
""" Method to capture raw_input
"""
- req = self.client.stdin_channel.get_msg(timeout=timeout)
+ req = run_sync(self.client.stdin_channel.get_msg)(timeout=timeout)
# in case any iopub came while we were waiting:
self.handle_iopub(msg_id)
if msg_id == req["parent_header"].get("msg_id"):