From 84a4c63f7c2b700357f5e5f730209dc4fc897c24 Mon Sep 17 00:00:00 2001
From: David Brochart <david.brochart@gmail.com>
Date: Wed, 2 Jun 2021 09:45:47 +0200
Subject: [PATCH] Use run_sync only from jupyter_client 7.0+
---
jupyter_console/completer.py | 12 +++++++++++-
jupyter_console/ptshell.py | 13 ++++++++++---
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/jupyter_console/completer.py b/jupyter_console/completer.py
index d0b7b9a..4b845e3 100644
--- a/jupyter_console/completer.py
+++ b/jupyter_console/completer.py
@@ -7,6 +7,16 @@
from traitlets.config import Configurable
from traitlets import Float
+import jupyter_client
+
+
+# jupyter_client 7.0+ has async channel methods that we expect to be sync here
+if jupyter_client._version.version_info[0] >= 7:
+ from jupyter_client.utils import run_sync
+else:
+ run_sync = lambda x: x
+
+
class ZMQCompleter(Configurable):
"""Client-side completion machinery.
@@ -31,7 +41,7 @@ def complete_request(self, code, cursor_pos):
cursor_pos=cursor_pos,
)
- msg = self.client.shell_channel.get_msg(timeout=self.timeout)
+ msg = run_sync(self.client.shell_channel.get_msg)(timeout=self.timeout)
if msg['parent_header']['msg_id'] == msg_id:
return msg['content']
diff --git a/jupyter_console/ptshell.py b/jupyter_console/ptshell.py
index d6dc1e7..4608992 100644
--- a/jupyter_console/ptshell.py
+++ b/jupyter_console/ptshell.py
@@ -76,7 +76,14 @@
from pygments.util import ClassNotFound
from pygments.token import Token
-from jupyter_client.utils import run_sync
+import jupyter_client
+
+
+# jupyter_client 7.0+ has async channel methods that we expect to be sync here
+if jupyter_client._version.version_info[0] >= 7:
+ from jupyter_client.utils import run_sync
+else:
+ run_sync = lambda x: x
def ask_yes_no(prompt, default=None, interrupt=None):
@@ -1034,6 +1041,6 @@ def double_int(sig, frame):
# only send stdin reply if there *was not* another request
# or execution finished while we were reading.
- if not (self.client.stdin_channel.msg_ready() or
- self.client.shell_channel.msg_ready()):
+ if not (run_sync(self.client.stdin_channel.msg_ready)() or
+ run_sync(self.client.shell_channel.msg_ready)()):
self.client.input(raw_data)