Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix weakref callback errors during finalization #123

Merged
merged 2 commits into from
Nov 1, 2023

Conversation

RazerM
Copy link
Contributor

@RazerM RazerM commented Oct 31, 2023

Using blinker 1.6.3, I get a lot of errors like the following when invoking the Flask CLI, running tests, etc.

Exception ignored in: <bound method Signal._cleanup_receiver of <blinker.base.NamedSignal object at 0x10a67ef90; 'request-started'>>
Traceback (most recent call last):
  File "/path/to/venv/lib/python3.7/site-packages/blinker/base.py", line 430, in _cleanup_receiver
TypeError: 'NoneType' object is not callable

The only issue I could find about this is one made for sentry: getsentry/sentry-python#2183

I found that the cause is on this line:

self._disconnect(t.cast(IdentityType, receiver_ref.receiver_id), ANY_ID)

During cleanup, t.cast is None.

weakref finalization callbacks need to follow __del__ rules, i.e.
any globals referenced may have had their attributes set to None.

weakref finalization callbacks need to follow __del__ rules, i.e.
any globals referenced may have had their attributes set to None.
@pgjones
Copy link
Member

pgjones commented Nov 1, 2023

Thanks, I'd be tempted to drop the usage of cast and simply type: ignore the lines in question. Do you think the cast usage is better?

Edit: I'll merge this - you've done the work and I don't have a strong view.

@pgjones pgjones merged commit fe3ec89 into pallets-eco:main Nov 1, 2023
7 checks passed
@RazerM
Copy link
Contributor Author

RazerM commented Nov 1, 2023

That was my first instinct, then I thought that type safety is good since exceptions here may be unraisable. I also don't have a strong view either way, but I think the reference to cast is safe.

Thanks for merging :-)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2023
@RazerM RazerM deleted the fix/weakref-cleanup-unraisable branch May 24, 2024 11:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants