Title: Missing critical sections for `PyDict_Next` calls in `_functoolsmodule.c` · Issue #145446 · python/cpython · GitHub
Open Graph Title: Missing critical sections for `PyDict_Next` calls in `_functoolsmodule.c` · Issue #145446 · python/cpython
X Title: Missing critical sections for `PyDict_Next` calls in `_functoolsmodule.c` · Issue #145446 · python/cpython
Description: Bug report Bug description: After some discussion on PR #145362, I noticed that in Modules/_functoolsmodule.c, all use cases of PyDict_Next do not use a critical section, which is necessary in for the free-threaded build. The docs say th...
Open Graph Description: Bug report Bug description: After some discussion on PR #145362, I noticed that in Modules/_functoolsmodule.c, all use cases of PyDict_Next do not use a critical section, which is necessary in for ...
X Description: Bug report Bug description: After some discussion on PR #145362, I noticed that in Modules/_functoolsmodule.c, all use cases of PyDict_Next do not use a critical section, which is necessary in for ...
Opengraph URL: https://github.com/python/cpython/issues/145446
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Missing critical sections for `PyDict_Next` calls in `_functoolsmodule.c`","articleBody":"# Bug report\n\n### Bug description:\n\nAfter some discussion on PR https://github.com/python/cpython/pull/145362, I noticed that in `Modules/_functoolsmodule.c`, all use cases of `PyDict_Next` do not use a critical section, which is necessary in for the free-threaded build. The [docs](https://docs.python.org/3/c-api/dict.html#c.PyDict_Next) say that for `PyDict_Next`:\n\n\u003e The function is not thread-safe in the [free-threaded](https://docs.python.org/3/glossary.html#term-free-threading) build without external synchronization. You can use [Py_BEGIN_CRITICAL_SECTION](https://docs.python.org/3/c-api/synchronization.html#c.Py_BEGIN_CRITICAL_SECTION) to lock the dictionary while iterating over it\n\nI 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_Next` that are not thread-safe, please let me know.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-145487\n* gh-145879\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/brijkapadia","@type":"Person","name":"brijkapadia"},"datePublished":"2026-03-03T02:19:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/145446/cpython/issues/145446"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:349ec1d5-a0b0-fa4d-ef07-0556c884b51b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9510:18BA88:73777A1:A22BE60:6A500CAB |
| html-safe-nonce | b789f401d69779b8c73b40a63d8513e0bb2a833b1fd284eab0cb4ca63a55d328 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTEwOjE4QkE4ODo3Mzc3N0ExOkEyMkJFNjA6NkE1MDBDQUIiLCJ2aXNpdG9yX2lkIjoiMzYzNzYwMTI4MDE1NzgxMzkzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4cbc4ee278df74aeb8c7d3691a9a789b703417b7eb625c8899d42b22b7ceddc4 |
| hovercard-subject-tag | issue:4014311747 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/145446/issue_layout |
| twitter:image | https://opengraph.githubassets.com/652203a9e900a98a7f048873601e92d0abc8d019b8ab7ebcc3c3281c278b9724/python/cpython/issues/145446 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/652203a9e900a98a7f048873601e92d0abc8d019b8ab7ebcc3c3281c278b9724/python/cpython/issues/145446 |
| og:image:alt | Bug report Bug description: After some discussion on PR #145362, I noticed that in Modules/_functoolsmodule.c, all use cases of PyDict_Next do not use a critical section, which is necessary in for ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brijkapadia |
| hostname | github.com |
| expected-hostname | github.com |
| None | 56eec25a3430492dd6ec2a480eb33256a0da5192d5714b0db4f5ab5f33203d94 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 93a615b89b7dcbdb6b678f4772931ecc28ada82a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width