Skip to content

Commit

Permalink
Merge pull request #174 from projectgus/bugfix/weakref_disconnect_shu…
Browse files Browse the repository at this point in the history
…tdown

Fix "Exception ignored" in weakref callback during interpreter shutdown.
  • Loading branch information
davidism authored Nov 8, 2024
2 parents dcce3e9 + 42561fd commit 16e4bd7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Unreleased
- Drop support for Python 3.8. :pr:`175`
- Remove previously deprecated ``__version__``, ``receiver_connected``,
``Signal.temporarily_connected_to`` and ``WeakNamespace``. :pr:`172`
- Skip weakref signal cleanup if the interpreter is shutting down.
:issue:`173`


Version 1.8.2
Expand Down
6 changes: 5 additions & 1 deletion src/blinker/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import collections.abc as c
import sys
import typing as t
import weakref
from collections import defaultdict
Expand Down Expand Up @@ -403,7 +404,10 @@ def _make_cleanup_receiver(
"""

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

return cleanup

Expand Down

0 comments on commit 16e4bd7

Please sign in to comment.