@@ -188,6 +188,11 @@ def cwd_for_path(self, path):
188
188
os_path = os .path .dirname (os_path )
189
189
return os_path
190
190
191
+ async def _remove_kernel_when_ready (self , kernel_id , kernel_awaitable ):
192
+ await super ()._remove_kernel_when_ready (kernel_id , kernel_awaitable )
193
+ self ._kernel_connections .pop (kernel_id , None )
194
+ self ._kernel_ports .pop (kernel_id , None )
195
+
191
196
async def start_kernel (self , kernel_id = None , path = None , ** kwargs ):
192
197
"""Start a kernel for a session and return its kernel_id.
193
198
@@ -384,19 +389,12 @@ def shutdown_kernel(self, kernel_id, now=False, restart=False):
384
389
self ._check_kernel_id (kernel_id )
385
390
self .stop_watching_activity (kernel_id )
386
391
self .stop_buffering (kernel_id )
387
- self ._kernel_connections .pop (kernel_id , None )
388
392
389
393
# Decrease the metric of number of kernels
390
394
# running for the relevant kernel type by 1
391
395
KERNEL_CURRENTLY_RUNNING_TOTAL .labels (type = self ._kernels [kernel_id ].kernel_name ).dec ()
392
396
393
397
self .pinned_superclass .shutdown_kernel (self , kernel_id , now = now , restart = restart )
394
- # Unlike its async sibling method in AsyncMappingKernelManager, removing the kernel_id
395
- # from the connections dictionary isn't as problematic before the shutdown since the
396
- # method is synchronous. However, we'll keep the relative call orders the same from
397
- # a maintenance perspective.
398
- self ._kernel_connections .pop (kernel_id , None )
399
- self ._kernel_ports .pop (kernel_id , None )
400
398
401
399
async def restart_kernel (self , kernel_id , now = False ):
402
400
"""Restart a kernel by kernel_id"""
@@ -655,6 +653,4 @@ async def shutdown_kernel(self, kernel_id, now=False, restart=False):
655
653
ret = await self .pinned_superclass .shutdown_kernel (
656
654
self , kernel_id , now = now , restart = restart
657
655
)
658
- self ._kernel_connections .pop (kernel_id , None )
659
- self ._kernel_ports .pop (kernel_id , None )
660
656
return ret
0 commit comments