Skip to content

Commit ab64452

Browse files
committed
Backport PR #4412: Enable restart_kernel for async usage
Converted `MappingKernelManager.restart_kernel` to a coroutine so that projects that take advantage of async kernel startup can also realize appropriate behavior relative to restarts. To take full advantage of async kernel startup (with restarts), this PR along with its "[sibling PR](jupyter/jupyter_client#425)" will be required. Please note, however, that each of these PRs can be independently installed w/o affecting today's notebook applications (as far as I can determine via testing the possible combinations). That said, BOTH of these PRs will be required for usage by Enterprise Gateway - which incurs very long kernel startup times - or other projects that require concurrent kernel starts. It would be ideal to have this PR back-ported to python 2.7-relative release since EG has an immediate need. Signed-off-by: Min RK <[email protected]>
1 parent daa1bde commit ab64452

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

notebook/services/kernels/kernelmanager.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,11 @@ def shutdown_kernel(self, kernel_id, now=False):
280280
self.last_kernel_activity = utcnow()
281281
return super(MappingKernelManager, self).shutdown_kernel(kernel_id, now=now)
282282

283+
@gen.coroutine
283284
def restart_kernel(self, kernel_id):
284285
"""Restart a kernel by kernel_id"""
285286
self._check_kernel_id(kernel_id)
286-
super(MappingKernelManager, self).restart_kernel(kernel_id)
287+
yield gen.maybe_future(super(MappingKernelManager, self).restart_kernel(kernel_id))
287288
kernel = self.get_kernel(kernel_id)
288289
# return a Future that will resolve when the kernel has successfully restarted
289290
channel = kernel.connect_shell()
@@ -319,7 +320,7 @@ def on_restart_failed():
319320
channel.on_recv(on_reply)
320321
loop = IOLoop.current()
321322
timeout = loop.add_timeout(loop.time() + self.kernel_info_timeout, on_timeout)
322-
return future
323+
raise gen.Return(future)
323324

324325
def notify_connect(self, kernel_id):
325326
"""Notice a new connection to a kernel"""

0 commit comments

Comments
 (0)