Skip to content

Commit

Permalink
Changes necessary to get async kernel startup working
Browse files Browse the repository at this point in the history
Inspired by jupyter#402, but needing support for python 2.7, these changes
essentially apply the same model used in Notebook for supporting
coroutines with appropriately placed yield statements in order to
start multiple kernels simultaneously with the same server instance.
  • Loading branch information
kevin-bates committed Feb 16, 2019
1 parent e813086 commit 633f245
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions jupyter_client/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import time

import zmq

from tornado import gen
from ipython_genutils.importstring import import_item
from .localinterfaces import is_local_ip, local_ips
from traitlets import (
Expand Down Expand Up @@ -205,6 +205,7 @@ def _close_control_socket(self):
self._control_socket.close()
self._control_socket = None

@gen.coroutine
def start_kernel(self, **kw):
"""Starts a kernel on this host in a separate process.
Expand Down Expand Up @@ -246,8 +247,7 @@ def start_kernel(self, **kw):

# launch the kernel subprocess
self.log.debug("Starting kernel: %s", kernel_cmd)
self.kernel = self._launch_kernel(kernel_cmd, env=env,
**kw)
self.kernel = yield gen.maybe_future(self._launch_kernel(kernel_cmd, env=env, **kw))
self.start_restarter()
self._connect_control_socket()

Expand Down
7 changes: 4 additions & 3 deletions jupyter_client/multikernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import os
import uuid

import zmq

from tornado import gen
from traitlets.config.configurable import LoggingConfigurable
from ipython_genutils.importstring import import_item
from traitlets import (
Expand Down Expand Up @@ -82,6 +82,7 @@ def __len__(self):
def __contains__(self, kernel_id):
return kernel_id in self._kernels

@gen.coroutine
def start_kernel(self, kernel_name=None, **kwargs):
"""Start a new kernel.
Expand All @@ -107,9 +108,9 @@ def start_kernel(self, kernel_name=None, **kwargs):
parent=self, log=self.log, kernel_name=kernel_name,
**constructor_kwargs
)
km.start_kernel(**kwargs)
yield gen.maybe_future(km.start_kernel(**kwargs))
self._kernels[kernel_id] = km
return kernel_id
raise gen.Return(kernel_id)

@kernel_method
def shutdown_kernel(self, kernel_id, now=False, restart=False):
Expand Down

0 comments on commit 633f245

Please sign in to comment.