Skip to content

Commit 7a8d996

Browse files
committed
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.
1 parent d8eee6a commit 7a8d996

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

jupyter_server/services/kernels/kernelmanager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,11 @@ def shutdown_kernel(self, kernel_id, now=False):
306306

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

309+
@gen.coroutine
309310
def restart_kernel(self, kernel_id):
310311
"""Restart a kernel by kernel_id"""
311312
self._check_kernel_id(kernel_id)
312-
super(MappingKernelManager, self).restart_kernel(kernel_id)
313+
yield gen.maybe_future(super(MappingKernelManager, self).restart_kernel(kernel_id))
313314
kernel = self.get_kernel(kernel_id)
314315
# return a Future that will resolve when the kernel has successfully restarted
315316
channel = kernel.connect_shell()
@@ -345,7 +346,7 @@ def on_restart_failed():
345346
channel.on_recv(on_reply)
346347
loop = IOLoop.current()
347348
timeout = loop.add_timeout(loop.time() + self.kernel_info_timeout, on_timeout)
348-
return future
349+
raise gen.Return(future)
349350

350351
def notify_connect(self, kernel_id):
351352
"""Notice a new connection to a kernel"""

0 commit comments

Comments
 (0)