Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Restart In Place API Support #1314

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jupyter_server/services/kernels/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ async def post(self, kernel_id, action):
if action == "interrupt":
await ensure_async(km.interrupt_kernel(kernel_id))
self.set_status(204)
if action == "restart":
if action == "restart" or action == "restart-in-place":
try:
await km.restart_kernel(kernel_id)
await km.restart_kernel(kernel_id, restart_in_place=action == "restart-in-place")
except Exception as e:
message = "Exception restarting kernel"
self.log.error(message, exc_info=True)
Expand All @@ -113,7 +113,7 @@ async def post(self, kernel_id, action):
# URL to handler mappings
# -----------------------------------------------------------------------------
_kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)"
_kernel_action_regex = r"(?P<action>restart|interrupt)"
_kernel_action_regex = r"(?P<action>restart|interrupt|restart-in-place)"

default_handlers = [
(r"/api/kernels", MainKernelHandler),
Expand Down
6 changes: 4 additions & 2 deletions jupyter_server/services/kernels/kernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,12 @@ async def _async_shutdown_kernel(self, kernel_id, now=False, restart=False):

shutdown_kernel = _async_shutdown_kernel

async def _async_restart_kernel(self, kernel_id, now=False):
async def _async_restart_kernel(self, kernel_id, now=False, restart_in_place=False):
"""Restart a kernel by kernel_id"""
self._check_kernel_id(kernel_id)
await self.pinned_superclass._async_restart_kernel(self, kernel_id, now=now)
await self.pinned_superclass._async_restart_kernel(
self, kernel_id, now=now, restart_in_place=restart_in_place
)
kernel = self.get_kernel(kernel_id)
# return a Future that will resolve when the kernel has successfully restarted
channel = kernel.connect_shell()
Expand Down
Loading