Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
GH-91636: Clear weakrefs created by finalizers.#136401
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
GH-91636: Clear weakrefs created by finalizers. #136401
Conversation
nascheme commented Jul 8, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Weakrefs to unreachable garbage that are created during running of finalizers need to be cleared. This avoids exposing objects that have `tp_clear` called on them to Python-level code.
nascheme commented Jul 8, 2025
@colesbury In case you want to look at the free_threading_gc changes. |
sergey-miryanov commented Jul 8, 2025
Looks good to me. |
Uh oh!
There was an error while loading. Please reload this page.
Add a boolean flag to indicate that callbacks should be enabled. This allows the same function to be used before and after finalizer execution.
| if (!allow_callbacks){ | ||
| return0; | ||
| } | ||
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar question: The old and allow_callbacks arguments are orthogonal even in older versions?
b6b99bf into python:mainUh oh!
There was an error while loading. Please reload this page.
Weakrefs to unreachable garbage that are created during running of finalizers need to be cleared. This avoids exposing objects that have `tp_clear` called on them to Python-level code.
Weakrefs to unreachable garbage that are created during running of finalizers need to be cleared. This avoids exposing objects that have `tp_clear` called on them to Python-level code.
Weakrefs to unreachable garbage that are created during running of finalizers need to be cleared. This avoids exposing objects that have `tp_clear` called on them to Python-level code.
Weakrefs to unreachable garbage that are created during running of finalizers need to be cleared. This avoids exposing objects that have `tp_clear` called on them to Python-level code.
Weakrefs to unreachable garbage that are created during running of finalizers need to be cleared. This avoids exposing objects that have `tp_clear` called on them to Python-level code.
sergey-miryanov commented Sep 3, 2025
nascheme commented Sep 4, 2025
Yeah, you are right. I think it would be good to backport this one. |
hugovk commented Sep 11, 2025
This bug had been around for a while, let's wait for 3.14.1 for the backport rather than do it during RC. |
sergey-miryanov commented Nov 25, 2025
@hugovk It's about 3.14.1 here. Should we backport this PR? I'm not sure about the process. Is it enough to add backport labels? |
hugovk commented Nov 26, 2025
@sergey-miryanov Yeah, please add the labels and Miss Islington will attempt backports. And then we can carefully review the backport PRs. |
Thanks @nascheme for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
Thanks @nascheme for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Weakrefs to unreachable garbage that are created during running of finalizers need to be cleared. This avoids exposing objects that have `tp_clear` called on them to Python-level code. (cherry picked from commit b6b99bf) Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
Sorry, @nascheme, I could not cleanly backport this to |
GH-141993 is a backport of this pull request to the 3.14 branch. |
sergey-miryanov commented Nov 26, 2025
…141993) GH-91636: Clear weakrefs created by finalizers. (GH-136401) Weakrefs to unreachable garbage that are created during running of finalizers need to be cleared. This avoids exposing objects that have `tp_clear` called on them to Python-level code. (cherry picked from commit b6b99bf) Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
serhiy-storchaka commented Dec 26, 2025
Reminder about backporting to 3.13. |
sergey-miryanov commented Jan 23, 2026
Thanks for reminder. Sorry for the delay. Will work on backporting this weekends. |
GH-144214 is a backport of this pull request to the 3.13 branch. |
Weakrefs to unreachable garbage that are created during running of finalizers need to be cleared. This avoids exposing objects that have
tp_clearcalled on them to Python-level code.Note that this is part of the GH-136189 change, split out to make it easier for back-porting. This change is conceptually quite simple and is a candidate to backport to all older Python versions (this bug existed for a long time, perhaps in version 2.3). There is some duplicated code between
handle_finalizersandclear_finalizersbut I think it's simpler just to leave that duplication. In the "main" branch I'll clean that up.