Skip to content

Commit

Permalink
Rework logic for wait_for_ready
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainCorlay committed Dec 9, 2020
1 parent 996b53e commit 7a063dc
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 7 deletions.
111 changes: 111 additions & 0 deletions Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"print(1)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"print(1)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"print(1)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"print(1)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"print(1)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n"
]
}
],
"source": [
"print(1)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n"
]
}
],
"source": [
"print(1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
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:
await self.iopub_channel.get_msg(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:
self.iopub_channel.get_msg(block=True, 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 7a063dc

Please sign in to comment.