Skip to content

Commit 5537672

Browse files
committed
Wrap jupyter_client's async functions with run_sync
1 parent 64f1695 commit 5537672

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

jupyter_console/ptshell.py

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

79+
from jupyter_client.utils import run_sync
80+
7981

8082
def ask_yes_no(prompt, default=None, interrupt=None):
8183
"""Asks a question and returns a boolean (y/n) answer.
@@ -705,8 +707,8 @@ def run_cell(self, cell, store_history=True):
705707
return
706708

707709
# flush stale replies, which could have been ignored, due to missed heartbeats
708-
while self.client.shell_channel.msg_ready():
709-
self.client.shell_channel.get_msg()
710+
while run_sync(self.client.shell_channel.msg_ready)():
711+
run_sync(self.client.shell_channel.get_msg)()
710712
# execute takes 'hidden', which is the inverse of store_hist
711713
msg_id = self.client.execute(cell, not store_history)
712714

@@ -739,7 +741,7 @@ def run_cell(self, cell, store_history=True):
739741
#-----------------
740742

741743
def handle_execute_reply(self, msg_id, timeout=None):
742-
msg = self.client.shell_channel.get_msg(block=False, timeout=timeout)
744+
msg = run_sync(self.client.shell_channel.get_msg)(block=False, timeout=timeout)
743745
if msg["parent_header"].get("msg_id", None) == msg_id:
744746

745747
self.handle_iopub(msg_id)
@@ -778,7 +780,7 @@ def handle_is_complete_reply(self, msg_id, timeout=None):
778780
## Get the is_complete response:
779781
msg = None
780782
try:
781-
msg = self.client.shell_channel.get_msg(block=True, timeout=timeout)
783+
msg = run_sync(self.client.shell_channel.get_msg)(block=True, timeout=timeout)
782784
except Empty:
783785
warn('The kernel did not respond to an is_complete_request. '
784786
'Setting `use_kernel_is_complete` to False.')
@@ -849,8 +851,8 @@ def handle_iopub(self, msg_id=''):
849851
850852
It only displays output that is caused by this session.
851853
"""
852-
while self.client.iopub_channel.msg_ready():
853-
sub_msg = self.client.iopub_channel.get_msg()
854+
while run_sync(self.client.iopub_channel.msg_ready)():
855+
sub_msg = run_sync(self.client.iopub_channel.get_msg)()
854856
msg_type = sub_msg['header']['msg_type']
855857

856858
# Update execution_count in case it changed in another session
@@ -1003,7 +1005,7 @@ def handle_image_callable(self, data, mime):
10031005
def handle_input_request(self, msg_id, timeout=0.1):
10041006
""" Method to capture raw_input
10051007
"""
1006-
req = self.client.stdin_channel.get_msg(timeout=timeout)
1008+
req = run_sync(self.client.stdin_channel.get_msg)(timeout=timeout)
10071009
# in case any iopub came while we were waiting:
10081010
self.handle_iopub(msg_id)
10091011
if msg_id == req["parent_header"].get("msg_id"):

0 commit comments

Comments
 (0)