Skip to content

Commit de8d2c5

Browse files
committed
in shutdown remove kernels that raise exceptions
1 parent 94595af commit de8d2c5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

jupyter_client/multikernelmanager.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,11 @@ async def _async_shutdown_kernel(
239239
restart : bool
240240
Will the kernel be restarted?
241241
"""
242-
# If the kernel in a pending state?
243242
self.log.info("Kernel shutdown: %s" % kernel_id)
243+
# If we're using pending kernels, block shutdown when a kernel is pending.
244244
if self._using_pending_kernels() and kernel_id in self._pending_kernels:
245245
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.
246247
elif kernel_id in self._pending_kernels:
247248
kernel = self._pending_kernels[kernel_id]
248249
try:
@@ -251,6 +252,10 @@ async def _async_shutdown_kernel(
251252
self.remove_kernel(kernel_id)
252253
return
253254
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
254259
stopper = ensure_async(km.shutdown_kernel(now, restart))
255260
fut = asyncio.ensure_future(self._remove_kernel_when_ready(kernel_id, stopper))
256261
self._pending_kernels[kernel_id] = fut

0 commit comments

Comments
 (0)