Added some guards against ``KeyError`` in the event system to accommodate
the case that the interpreter is shutting down at the same time
:meth:`_engine.Engine.dispose` is being called, which would cause stack
trace warnings.
Fixes: #6740
Change-Id: I2c42e9edac2371e68b39d8360494c5fddfd6cd8c
--- /dev/null
+.. change::
+ :tags: bug, engine
+ :tickets: 6740
+
+ Added some guards against ``KeyError`` in the event system to accommodate
+ the case that the interpreter is shutting down at the same time
+ :meth:`_engine.Engine.dispose` is being called, which would cause stack
+ trace warnings.
+
for listen_fn in elements:
listen_ref = weakref.ref(listen_fn)
- key = old_listener_to_key[listen_ref]
- dispatch_reg = _key_to_collection[key]
+ try:
+ key = old_listener_to_key[listen_ref]
+ except KeyError:
+ # can occur during interpreter shutdown.
+ # see #6740
+ continue
+
+ try:
+ dispatch_reg = _key_to_collection[key]
+ except KeyError:
+ continue
+
if newowner in dispatch_reg:
assert dispatch_reg[newowner] == listen_ref
else: