GeezerVison is showing github.com — gh-149816: Fix another variant of race on setattr/managed dict going … by DinoV · Pull Request #160278 · python/cpython
Conversation
DinoV
commented
Oct 22, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There's a couple of remaining issues with doing a setaddr. If we have a split dictionary we're not increfing the dictionary. Also, when we insert a split key it takes a lock which can cause the object/dict locks to be released so we need to guard against that.
The code here is pretty complex so it's also an attempt to simplify it. _PyObject_StoreInstanceAttribute loses any Py_GIL_DISABLEd ifdef's, instead we just have the main path with Py_BEGIN_CRITICAL_SECTION and FT_ATOMIC_LOAD_UINT8 and so on just turn into nothing when we're in the free threaded build.
I've also just updated things to go directly to _PyDict_SetItem_LockHeld when we're doing the dictionary version and made store_instance_attr_lock_held only be used when we don't have a materialized dictionary. Going through the fast split dictionary case it dictinsert isn't substantially different but it really complicates reasoning about what's going on here and causes `store_instance_attr_lock_held to need to handle a lot more cases.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
methane
Awaiting requested review from methane
methane will be requested when the pull request is marked ready for review
methane is a code owner
markshannon
Awaiting requested review from markshannon
markshannon will be requested when the pull request is marked ready for review
markshannon is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.