Repository navigation
gh-144446: Fix thread-safety of FrameLocalsProxy on executing frames - #156973
Open
kumaraditya303 wants to merge 6 commits into
Open
kumaraditya303 wants to merge 6 commits into
kumaraditya303 wants to merge 6 commits into
Conversation
…rames Synchronize FrameLocalsProxy accesses with the frame's owning thread: accessors run under the frame object's critical section and stop the world when the frame is executing on another thread. Co-authored-by: Sam Gross <colesbury@gmail.com>
mpage
reviewed
Sep 9, 2026
| if (_stw) { \ | ||
| PyInterpreterState *interp = _PyInterpreterState_GET(); \ | ||
| _PyEval_StopTheWorld(interp); \ | ||
| RESULT = CALL; \ |
Contributor
There was a problem hiding this comment.
I don't think this is safe. CALL can end up executing arbitrary Python code via __hash__, which we shouldn't do while the world is stopped.
mpage
approved these changes
Oct 7, 2026
mpage
left a comment
Contributor
There was a problem hiding this comment.
Putting this back on your queue
ambv
requested changes
Oct 21, 2026
ambv
left a comment
Contributor
There was a problem hiding this comment.
I think Matt meant to request changes.
|
When you're done making the requested changes, leave the comment: |
|
🤖 New build scheduled with the buildbot fleet by @kumaraditya303 for commit e94a203 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F156973%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
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.
Synchronize FrameLocalsProxy accesses with the frame's owning thread: fast locals are accessed under the frame object's critical section, and with the world stopped when the frame may be executing on another thread.
Changes:
__hash__/__eq__) runs outside it, so no Python code is executed while the world is stopped.keys(),values(),items()andlen()snapshot the fast locals in the region and hold the extra locals dict's critical section while iterating it.PyFrame_GetVaris synchronized the same way.Co-authored-by: Sam Gross colesbury@gmail.com