Skip to content

Commit 84a4c63

Browse files
committed
Use run_sync only from jupyter_client 7.0+
1 parent 0c7aca0 commit 84a4c63

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

jupyter_console/completer.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
from traitlets.config import Configurable
88
from traitlets import Float
99

10+
import jupyter_client
11+
12+
13+
# jupyter_client 7.0+ has async channel methods that we expect to be sync here
14+
if jupyter_client._version.version_info[0] >= 7:
15+
from jupyter_client.utils import run_sync
16+
else:
17+
run_sync = lambda x: x
18+
19+
1020
class ZMQCompleter(Configurable):
1121
"""Client-side completion machinery.
1222
@@ -31,7 +41,7 @@ def complete_request(self, code, cursor_pos):
3141
cursor_pos=cursor_pos,
3242
)
3343

34-
msg = self.client.shell_channel.get_msg(timeout=self.timeout)
44+
msg = run_sync(self.client.shell_channel.get_msg)(timeout=self.timeout)
3545
if msg['parent_header']['msg_id'] == msg_id:
3646
return msg['content']
3747

jupyter_console/ptshell.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@
7676
from pygments.util import ClassNotFound
7777
from pygments.token import Token
7878

79-
from jupyter_client.utils import run_sync
79+
import jupyter_client
80+
81+
82+
# jupyter_client 7.0+ has async channel methods that we expect to be sync here
83+
if jupyter_client._version.version_info[0] >= 7:
84+
from jupyter_client.utils import run_sync
85+
else:
86+
run_sync = lambda x: x
8087

8188

8289
def ask_yes_no(prompt, default=None, interrupt=None):
@@ -1034,6 +1041,6 @@ def double_int(sig, frame):
10341041

10351042
# only send stdin reply if there *was not* another request
10361043
# or execution finished while we were reading.
1037-
if not (self.client.stdin_channel.msg_ready() or
1038-
self.client.shell_channel.msg_ready()):
1044+
if not (run_sync(self.client.stdin_channel.msg_ready)() or
1045+
run_sync(self.client.shell_channel.msg_ready)()):
10391046
self.client.input(raw_data)

0 commit comments

Comments
 (0)