Skip to content

Commit

Permalink
Change logic of wait_for_ready to wait for the IOPub to be subscribed
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainCorlay committed Dec 9, 2020
1 parent 778fa85 commit 6d41ead
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
11 changes: 9 additions & 2 deletions jupyter_client/asynchronous/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,21 @@ async def wait_for_ready(self, timeout=None):

# Wait for kernel info reply on shell channel
while True:
self.kernel_info()
try:
msg = await self.shell_channel.get_msg(timeout=1)
except Empty:
pass
else:
if msg['msg_type'] == 'kernel_info_reply':
self._handle_kernel_info_reply(msg)
break
# Checking that IOPub is connected. If it is not connected, start over.
try:
iopub_msg = await self.iopub_channel.get_msg(block=True, timeout=0.2)
except Empty:
pass
else:
self._handle_kernel_info_reply(msg)
break

if not await self.is_alive():
raise RuntimeError('Kernel died before replying to kernel_info')
Expand Down
11 changes: 9 additions & 2 deletions jupyter_client/blocking/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,21 @@ def wait_for_ready(self, timeout=None):

# Wait for kernel info reply on shell channel
while True:
self.kernel_info()
try:
msg = self.shell_channel.get_msg(block=True, timeout=1)
except Empty:
pass
else:
if msg['msg_type'] == 'kernel_info_reply':
self._handle_kernel_info_reply(msg)
break
# Checking that IOPub is connected. If it is not connected, start over.
try:
iopub_msg = self.iopub_channel.get_msg(timeout=0.2)
except Empty:
pass
else:
self._handle_kernel_info_reply(msg)
break

if not self.is_alive():
raise RuntimeError('Kernel died before replying to kernel_info')
Expand Down
5 changes: 2 additions & 3 deletions jupyter_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ def start_channels(self, shell=True, iopub=True, stdin=True, hb=True, control=Tr
:meth:`start_kernel`. If the channels have been stopped and you
call this, :class:`RuntimeError` will be raised.
"""
if shell:
self.shell_channel.start()
self.kernel_info()
if iopub:
self.iopub_channel.start()
if shell:
self.shell_channel.start()
if stdin:
self.stdin_channel.start()
self.allow_stdin = True
Expand Down

0 comments on commit 6d41ead

Please sign in to comment.