gh-102960: Make frames weak-referenceable#152838
Open
ambv wants to merge 3 commits into
Open
Conversation
Add an explicit f_weakreflist field to the frame object, following the same pattern as generators and coroutines, including free-threading-safe weakref clearing via FT_CLEAR_WEAKREFS() in frame_dealloc(). Py_TPFLAGS_MANAGED_WEAKREF is not used because static builtin types must not carry it (see init_static_type()) and the pre-header would cost two extra words per frame instead of one. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Documentation build overview
|
Exceptions raised in worker threads don't propagate to the unittest result, so report weakref mismatches via a shared list instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Under --parallel-threads a concurrent collection can turn a test's own gc.collect() into a no-op, leaving its cycles uncollected. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
| Frames support weak references (gh-102960). | ||
| """ | ||
|
|
||
| def make_frame(self): |
Contributor
There was a problem hiding this comment.
Do we really need so many tests for this? A single test which verifies that frame objects are weakrefable and that when a frame dies the weakrefs gets cleared should be enough for this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Frame objects now support weak references, stored in an explicit
f_weakreflistfield, following the same pattern as generators and coroutines. Weakref clearing inframe_dealloc()usesFT_CLEAR_WEAKREFS(), which handles the free-threaded build correctly (unconditionalPyObject_ClearWeakRefs()there, NULL-check fast path on the default build).Py_TPFLAGS_MANAGED_WEAKREFwas considered instead, but static builtin types must not carry it (seeinit_static_type()), and the managed pre-header would cost two extra words per frame object instead of one.This is a redo of GH-102962 against current
main. Compared to that PR it adds free-threading-safe weakref clearing, a more comprehensive test suite, and docs.Tested on the default, free-threaded (
--disable-gil), and JIT (--enable-experimental-jit) builds.🤖 Generated with Claude Code