Skip to content

Commit

Permalink
Enable restart_kernel for async usage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kevin-bates authored and Zsailer committed Sep 27, 2019
1 parent 3332211 commit 297eb09
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions jupyter_server/services/kernels/kernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,11 @@ def shutdown_kernel(self, kernel_id, now=False):

return super(MappingKernelManager, self).shutdown_kernel(kernel_id, now=now)

@gen.coroutine
def restart_kernel(self, kernel_id):
"""Restart a kernel by kernel_id"""
self._check_kernel_id(kernel_id)
super(MappingKernelManager, self).restart_kernel(kernel_id)
yield gen.maybe_future(super(MappingKernelManager, self).restart_kernel(kernel_id))
kernel = self.get_kernel(kernel_id)
# return a Future that will resolve when the kernel has successfully restarted
channel = kernel.connect_shell()
Expand Down Expand Up @@ -345,7 +346,7 @@ def on_restart_failed():
channel.on_recv(on_reply)
loop = IOLoop.current()
timeout = loop.add_timeout(loop.time() + self.kernel_info_timeout, on_timeout)
return future
raise gen.Return(future)

def notify_connect(self, kernel_id):
"""Notice a new connection to a kernel"""
Expand Down

0 comments on commit 297eb09

Please sign in to comment.