@@ -313,7 +313,12 @@ def shutdown_kernel(self, kernel_id, now=False, restart=False):
313313 type = self ._kernels [kernel_id ].kernel_name
314314 ).dec ()
315315
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 )
317322
318323 async def restart_kernel (self , kernel_id , now = False ):
319324 """Restart a kernel by kernel_id"""
@@ -388,8 +393,11 @@ def list_kernels(self):
388393 kernels = []
389394 kernel_ids = self .pinned_superclass .list_kernel_ids (self )
390395 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
393401 return kernels
394402
395403 # override _check_kernel_id to raise 404 instead of KeyError
0 commit comments