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

[Gateway] Track only this server's kernels #5980

Merged
merged 1 commit into from
Apr 21, 2021
Merged
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
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