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

Prepare for jupyter_client 7.0 #244

Merged
merged 5 commits into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 11 additions & 1 deletion jupyter_console/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
davidbrochart marked this conversation as resolved.
Show resolved Hide resolved
from jupyter_client.utils import run_sync
else:
run_sync = lambda x: x


class ZMQCompleter(Configurable):
"""Client-side completion machinery.

Expand All @@ -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']

Expand Down
27 changes: 18 additions & 9 deletions jupyter_console/ptshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@
from pygments.util import ClassNotFound
from pygments.token import Token

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):
"""Asks a question and returns a boolean (y/n) answer.
Expand Down Expand Up @@ -705,8 +714,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)

Expand Down Expand Up @@ -739,7 +748,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)
Expand Down Expand Up @@ -778,7 +787,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.')
Expand Down Expand Up @@ -849,8 +858,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
Expand Down Expand Up @@ -1003,7 +1012,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"):
Expand Down Expand Up @@ -1032,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)