Skip to content

Commit

Permalink
Wrap jupyter_client's async functions with run_sync
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Jun 1, 2021
1 parent 64f1695 commit 5537672
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions jupyter_console/ptshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"):
Expand Down

0 comments on commit 5537672

Please sign in to comment.