diff --git a/Untitled.ipynb b/Untitled.ipynb new file mode 100644 index 000000000..042860157 --- /dev/null +++ b/Untitled.ipynb @@ -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 +} diff --git a/jupyter_client/asynchronous/client.py b/jupyter_client/asynchronous/client.py index c4ab1f179..1a21e3ac8 100644 --- a/jupyter_client/asynchronous/client.py +++ b/jupyter_client/asynchronous/client.py @@ -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') diff --git a/jupyter_client/blocking/client.py b/jupyter_client/blocking/client.py index 0779c225c..5f11b798a 100644 --- a/jupyter_client/blocking/client.py +++ b/jupyter_client/blocking/client.py @@ -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') diff --git a/jupyter_client/client.py b/jupyter_client/client.py index 347766b29..760ac5266 100644 --- a/jupyter_client/client.py +++ b/jupyter_client/client.py @@ -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