Repository navigation
Missing critical sections for PyDict_Next calls in _functoolsmodule.c #145446
Copy link
Copy link
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Mar 3, 2026 - addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancementand removedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Mar 3, 2026 - addedpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
on Mar 3, 2026 Sorry, I re-read your issue, you mean make
_functoolsmodulethread-safe when callingPyDict_Nextby adding a critical section? The title is a little bit misleading 😂 Updated the title, and please feel free to modify it if I'm wrong.Reacted by Brij Kapadia- changed the title
[-]Make PyDict_Next thread-safe using a critical section[/-][+]Missing critical sections for `PyDict_Next` calls in `_functoolsmodule.c`[/+]on Mar 3, 2026 - addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errorand removedtype-featureA feature request or enhancementA feature request or enhancementpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
on Mar 3, 2026 Yes, sorry if I was not clear. I meant to wrap calls to
PyDict_Nextspecifically in_functools_modulein a critical section, not to add a critical section insidePyDict_Next. Thank you for changing the title.- added a commit that references this issue
on Mar 12, 2026 - added a commit that references this issue
on Mar 13, 2026
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
Bug description:
After some discussion on PR #145362, I noticed that in
Modules/_functoolsmodule.c, all use cases ofPyDict_Nextdo not use a critical section, which is necessary in for the free-threaded build. The docs say that forPyDict_Next:I have not checked if other files are missing a critical section, but it is definitely possible. I will draft a PR shortly for this issue in the coming days, but if anyone else finds other occurrences of
PyDict_Nextthat are not thread-safe, please let me know.CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
PyDict_Next#145487PyDict_Next(GH-145487) #145879