Skip to content

Commit 16e4bd7

Browse files
authored
Merge pull request #174 from projectgus/bugfix/weakref_disconnect_shutdown
Fix "Exception ignored" in weakref callback during interpreter shutdown.
2 parents dcce3e9 + 42561fd commit 16e4bd7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGES.rst

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Unreleased
66
- Drop support for Python 3.8. :pr:`175`
77
- Remove previously deprecated ``__version__``, ``receiver_connected``,
88
``Signal.temporarily_connected_to`` and ``WeakNamespace``. :pr:`172`
9+
- Skip weakref signal cleanup if the interpreter is shutting down.
10+
:issue:`173`
911

1012

1113
Version 1.8.2

src/blinker/base.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import collections.abc as c
4+
import sys
45
import typing as t
56
import weakref
67
from collections import defaultdict
@@ -403,7 +404,10 @@ def _make_cleanup_receiver(
403404
"""
404405

405406
def cleanup(ref: weakref.ref[c.Callable[..., t.Any]]) -> None:
406-
self._disconnect(receiver_id, ANY_ID)
407+
# If the interpreter is shutting down, disconnecting can result in a
408+
# weird ignored exception. Don't call it in that case.
409+
if not sys.is_finalizing():
410+
self._disconnect(receiver_id, ANY_ID)
407411

408412
return cleanup
409413

0 commit comments

Comments
 (0)