@@ -313,7 +313,12 @@ def shutdown_kernel(self, kernel_id, now=False, restart=False):
313
313
type = self ._kernels [kernel_id ].kernel_name
314
314
).dec ()
315
315
316
- return self .pinned_superclass .shutdown_kernel (self , kernel_id , now = now , restart = restart )
316
+ self .pinned_superclass .shutdown_kernel (self , kernel_id , now = now , restart = restart )
317
+ # Unlike its async sibling method in AsyncMappingKernelManager, removing the kernel_id
318
+ # from the connections dictionary isn't as problematic before the shutdown since the
319
+ # method is synchronous. However, we'll keep the relative call orders the same from
320
+ # a maintenance perspective.
321
+ self ._kernel_connections .pop (kernel_id , None )
317
322
318
323
async def restart_kernel (self , kernel_id , now = False ):
319
324
"""Restart a kernel by kernel_id"""
@@ -388,8 +393,11 @@ def list_kernels(self):
388
393
kernels = []
389
394
kernel_ids = self .pinned_superclass .list_kernel_ids (self )
390
395
for kernel_id in kernel_ids :
391
- model = self .kernel_model (kernel_id )
392
- kernels .append (model )
396
+ try :
397
+ model = self .kernel_model (kernel_id )
398
+ kernels .append (model )
399
+ except (web .HTTPError , KeyError ):
400
+ pass # Probably due to a (now) non-existent kernel, continue building the list
393
401
return kernels
394
402
395
403
# override _check_kernel_id to raise 404 instead of KeyError
0 commit comments