Skip to content

Commit

Permalink
[Gateway] Track only this server's kernels
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-bates committed Feb 12, 2021
1 parent 6a3f4a7 commit bbe2744
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 11 additions & 5 deletions notebook/gateway/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,13 @@ async def get_kernel(self, kernel_id=None, **kwargs):
raise
else:
kernel = json_decode(response.body)
self._kernels[kernel_id] = kernel
self.log.debug("Kernel retrieved: %s" % kernel)
# Only update our models if we already know about this kernel
if kernel_id in self._kernels:
self._kernels[kernel_id] = kernel
self.log.debug("Kernel retrieved: %s", kernel)
else:
self.log.warning("Kernel '%s' is not managed by this instance.", kernel_id)
kernel = None
return kernel

async def kernel_model(self, kernel_id):
Expand All @@ -458,8 +463,9 @@ async def list_kernels(self, **kwargs):
self.log.debug("Request list kernels: %s", kernel_url)
response = await gateway_request(kernel_url, method='GET')
kernels = json_decode(response.body)
self._kernels = {x['id']: x for x in kernels}
return kernels
# Only update our models if we already know about the kernels
self._kernels = {x['id']: x for x in kernels if x['id'] in self._kernels}
return list(self._kernels.values())

async def shutdown_kernel(self, kernel_id, now=False, restart=False):
"""Shutdown a kernel by its kernel uuid.
Expand Down Expand Up @@ -512,7 +518,7 @@ def shutdown_all(self, now=False):
kwargs = {'method': 'DELETE'}
kwargs = GatewayClient.instance().load_connection_args(**kwargs)
client = HTTPClient()
for kernel_id in self._kernels.keys():
for kernel_id in self._kernels:
kernel_url = self._get_kernel_endpoint_url(kernel_id)
self.log.debug("Request delete kernel at: %s", kernel_url)
try:
Expand Down
3 changes: 2 additions & 1 deletion notebook/services/kernels/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ def post(self):
class KernelHandler(APIHandler):

@web.authenticated
@gen.coroutine
def get(self, kernel_id):
km = self.kernel_manager
model = km.kernel_model(kernel_id)
model = yield maybe_future(km.kernel_model(kernel_id))
self.finish(json.dumps(model, default=date_default))

@web.authenticated
Expand Down

0 comments on commit bbe2744

Please sign in to comment.