Skip to content

Commit

Permalink
flow kernel_id through start_kernel to enable reconnection/rehydratio…
Browse files Browse the repository at this point in the history
…n of gateway kernels (jupyter-server#788)
  • Loading branch information
Zsailer authored Apr 12, 2022
1 parent cc8bdf4 commit 64555ff
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions jupyter_server/gateway/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def start_kernel(self, kernel_id=None, path=None, **kwargs):
kwargs["cwd"] = self.cwd_for_path(path)

km = self.kernel_manager_factory(parent=self, log=self.log)
await km.start_kernel(**kwargs)
await km.start_kernel(kernel_id=kernel_id, **kwargs)
kernel_id = km.kernel_id
self._kernels[kernel_id] = km

Expand Down Expand Up @@ -368,6 +368,7 @@ async def refresh_model(self, model=None):
self.log.debug("Request kernel at: %s" % self.kernel_url)
try:
response = await gateway_request(self.kernel_url, method="GET")

except web.HTTPError as error:
if error.status_code == 404:
self.log.warning("Kernel not found at: %s" % self.kernel_url)
Expand Down Expand Up @@ -434,14 +435,14 @@ async def start_kernel(self, **kwargs):
response = await gateway_request(self.kernels_url, method="POST", body=json_body)
self.kernel = json_decode(response.body)
self.kernel_id = self.kernel["id"]
self.kernel_url = url_path_join(self.kernels_url, url_escape(str(self.kernel_id)))
self.log.info(f"GatewayKernelManager started kernel: {self.kernel_id}, args: {kwargs}")
else:
self.kernel_id = kernel_id
self.kernel_url = url_path_join(self.kernels_url, url_escape(str(self.kernel_id)))
self.kernel = await self.refresh_model()
self.log.info(f"GatewayKernelManager using existing kernel: {self.kernel_id}")

self.kernel_url = url_path_join(self.kernels_url, url_escape(str(self.kernel_id)))

async def shutdown_kernel(self, now=False, restart=False):
"""Attempts to stop the kernel process cleanly via HTTP."""

Expand Down

0 comments on commit 64555ff

Please sign in to comment.