@@ -109,15 +109,7 @@ def _starting_kernels(self):
109
109
def _context_default (self ) -> zmq .Context :
110
110
context = zmq .Context ()
111
111
# Use a finalizer to destroy the context.
112
- # self._finalizer = weakref.finalize(self, context.destroy)
113
-
114
- raise ValueError ('Notes here' )
115
- """
116
- The finalizer hangs because the context can't be destroyed.
117
- There are two other things that are probably contributing:
118
- - There is an open kernel subprocess at shutdown that is raising a warning on __del__
119
- - We are not properly canceling the _add_kernel_when_ready task
120
- """
112
+ self ._finalizer = weakref .finalize (self , context .destroy )
121
113
return context
122
114
123
115
connection_dir = Unicode ("" )
@@ -248,12 +240,14 @@ async def _async_shutdown_kernel(
248
240
await task
249
241
km = self .get_kernel (kernel_id )
250
242
await t .cast (asyncio .Future , km .ready )
243
+ except asyncio .exceptions .CancelledError :
244
+ pass
251
245
except Exception :
252
246
self .remove_kernel (kernel_id )
253
247
return
254
248
km = self .get_kernel (kernel_id )
255
249
# If a pending kernel raised an exception, remove it.
256
- if km .ready .exception ():
250
+ if not km . ready . cancelled () and km .ready .exception ():
257
251
self .remove_kernel (kernel_id )
258
252
return
259
253
stopper = ensure_async (km .shutdown_kernel (now , restart ))
@@ -310,7 +304,7 @@ async def _async_shutdown_all(self, now: bool = False) -> None:
310
304
await km .ready
311
305
except asyncio .exceptions .CancelledError :
312
306
self ._pending_kernels [km .kernel_id ].cancel ()
313
- except Exception as e :
307
+ except Exception :
314
308
# Will have been logged in _add_kernel_when_ready
315
309
pass
316
310
0 commit comments