File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -239,10 +239,11 @@ async def _async_shutdown_kernel(
239
239
restart : bool
240
240
Will the kernel be restarted?
241
241
"""
242
- # If the kernel in a pending state?
243
242
self .log .info ("Kernel shutdown: %s" % kernel_id )
243
+ # If we're using pending kernels, block shutdown when a kernel is pending.
244
244
if self ._using_pending_kernels () and kernel_id in self ._pending_kernels :
245
245
raise RuntimeError ("Kernel is in a pending state. Cannot shutdown." )
246
+ # If the kernel isn't in a ready state, wait for it to be ready.
246
247
elif kernel_id in self ._pending_kernels :
247
248
kernel = self ._pending_kernels [kernel_id ]
248
249
try :
@@ -251,6 +252,10 @@ async def _async_shutdown_kernel(
251
252
self .remove_kernel (kernel_id )
252
253
return
253
254
km = self .get_kernel (kernel_id )
255
+ # If a pending kernel raised an exception, remove it.
256
+ if km .ready .exception ():
257
+ self .remove_kernel (kernel_id )
258
+ return
254
259
stopper = ensure_async (km .shutdown_kernel (now , restart ))
255
260
fut = asyncio .ensure_future (self ._remove_kernel_when_ready (kernel_id , stopper ))
256
261
self ._pending_kernels [kernel_id ] = fut
You can’t perform that action at this time.
0 commit comments