Title: Possible data race in `dictiter_iternext` with with free-threading build · Issue #148873 · python/cpython · GitHub
Open Graph Title: Possible data race in `dictiter_iternext` with with free-threading build · Issue #148873 · python/cpython
X Title: Possible data race in `dictiter_iternext` with with free-threading build · Issue #148873 · python/cpython
Description: Bug description: With free-threading, it is possible to read di->di_dict, while it is being written. cpython/Objects/dictobject.c Lines 5611 to 5615 in f93834f static PyObject* dictiter_iternextkey(PyObject *self) { dictiterobject *di = ...
Open Graph Description: Bug description: With free-threading, it is possible to read di->di_dict, while it is being written. cpython/Objects/dictobject.c Lines 5611 to 5615 in f93834f static PyObject* dictiter_iternextkey...
X Description: Bug description: With free-threading, it is possible to read di->di_dict, while it is being written. cpython/Objects/dictobject.c Lines 5611 to 5615 in f93834f static PyObject* dictiter_iternext...
Opengraph URL: https://github.com/python/cpython/issues/148873
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Possible data race in `dictiter_iternext` with with free-threading build","articleBody":"### Bug description:\n\nWith free-threading, it is possible to read `di->di_dict`, while it is being written.\n\nhttps://github.com/python/cpython/blob/f93834ff01128774532c101c574e47c6c0418540/Objects/dictobject.c#L5611-L5615\n\nhttps://github.com/python/cpython/blob/f93834ff01128774532c101c574e47c6c0418540/Objects/dictobject.c#L5848-L5862\n\nReproducer: \n```python\nimport threading\n\nd = {str(i): i for i in range(1000)}\nit = iter(d)\n\nbarrier = threading.Barrier(2)\n\n\ndef run():\n barrier.wait()\n for _ in range(10000):\n try:\n next(it)\n except StopIteration:\n pass\n\n\nt1 = threading.Thread(target=run)\nt2 = threading.Thread(target=run)\nt1.start()\nt2.start()\nt1.join()\nt2.join()\n```\n\nTSAN report:\n```\nWARNING: ThreadSanitizer: data race (pid=2919507)\n Write of size 8 at 0x7fffb66d6bf0 by thread T2:\n #0 dictiter_iternextitem_lock_held /cpython/Objects/dictobject.c:5859:17 (python3.15t+0x2ada61) \n #1 dictiter_iternext_threadsafe /cpython/Objects/dictobject.c:5995:11 (python3.15t+0x2ada61)\n #2 dictiter_iternextkey /cpython/Objects/dictobject.c:5622:9 (python3.15t+0x2a2211) \n #3 builtin_next /cpython/Python/bltinmodule.c:1764:11 (python3.15t+0x423b62) \n #4 _Py_BuiltinCallFast_StackRef /cpython/Python/ceval.c:824:11 (python3.15t+0x43223d) \n #5 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:2409:35 (python3.15t+0x43223d)\n #6 _PyEval_EvalFrame /cpython/./Include/internal/pycore_ceval.h:118:16 (python3.15t+0x429900) \n #7 _PyEval_Vector /cpython/Python/ceval.c:2124:12 (python3.15t+0x429900)\n #8 _PyFunction_Vectorcall /cpython/Objects/call.c (python3.15t+0x21131f) \n #9 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x212e59) \n #10 _PyObject_VectorcallPrepend /cpython/Objects/call.c:855:20 (python3.15t+0x212e59)\n #11 method_vectorcall /cpython/Objects/classobject.c:55:12 (python3.15t+0x21638f) \n #12 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x481401) \n #13 context_run /cpython/Python/context.c:727:29 (python3.15t+0x481401)\n #14 method_vectorcall_FASTCALL_KEYWORDS /cpython/Objects/descrobject.c:421:24 (python3.15t+0x22b067) \n #15 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x210ca3) \n #16 PyObject_Vectorcall /cpython/Objects/call.c:327:12 (python3.15t+0x210ca3)\n #17 _Py_VectorCallInstrumentation_StackRefSteal /cpython/Python/ceval.c:775:11 (python3.15t+0x42a52c) \n #18 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:1846:35 (python3.15t+0x43031e) \n #19 _PyEval_EvalFrame /cpython/./Include/internal/pycore_ceval.h:118:16 (python3.15t+0x429900) \n #20 _PyEval_Vector /cpython/Python/ceval.c:2124:12 (python3.15t+0x429900)\n #21 _PyFunction_Vectorcall /cpython/Objects/call.c (python3.15t+0x21131f) \n #22 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x212e59) \n #23 _PyObject_VectorcallPrepend /cpython/Objects/call.c:855:20 (python3.15t+0x212e59)\n #24 method_vectorcall /cpython/Objects/classobject.c:55:12 (python3.15t+0x21638f) \n #25 _PyVectorcall_Call /cpython/Objects/call.c:273:16 (python3.15t+0x210fab) \n #26 _PyObject_Call /cpython/Objects/call.c:348:16 (python3.15t+0x210fab)\n #27 PyObject_Call /cpython/Objects/call.c:373:12 (python3.15t+0x211015) \n #28 thread_run /cpython/./Modules/_threadmodule.c:388:21 (python3.15t+0x606be2) \n #29 pythread_wrapper /cpython/Python/thread_pthread.h:234:5 (python3.15t+0x536447) \n\n Previous read of size 8 at 0x7fffb66d6bf0 by thread T1:\n #0 dictiter_iternextkey /cpython/Objects/dictobject.c:5615:27 (python3.15t+0x2a21f9) \n #1 builtin_next /cpython/Python/bltinmodule.c:1764:11 (python3.15t+0x423b62) \n #2 _Py_BuiltinCallFast_StackRef /cpython/Python/ceval.c:824:11 (python3.15t+0x43223d) \n #3 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:2409:35 (python3.15t+0x43223d)\n #4 _PyEval_EvalFrame /cpython/./Include/internal/pycore_ceval.h:118:16 (python3.15t+0x429900) \n #5 _PyEval_Vector /cpython/Python/ceval.c:2124:12 (python3.15t+0x429900)\n #6 _PyFunction_Vectorcall /cpython/Objects/call.c (python3.15t+0x21131f) \n #7 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x212e59) \n #8 _PyObject_VectorcallPrepend /cpython/Objects/call.c:855:20 (python3.15t+0x212e59)\n #9 method_vectorcall /cpython/Objects/classobject.c:55:12 (python3.15t+0x21638f) \n #10 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x481401) \n #11 context_run /cpython/Python/context.c:727:29 (python3.15t+0x481401)\n #12 method_vectorcall_FASTCALL_KEYWORDS /cpython/Objects/descrobject.c:421:24 (python3.15t+0x22b067) \n #13 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x210ca3) \n #14 PyObject_Vectorcall /cpython/Objects/call.c:327:12 (python3.15t+0x210ca3)\n #15 _Py_VectorCallInstrumentation_StackRefSteal /cpython/Python/ceval.c:775:11 (python3.15t+0x42a52c) \n #16 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:1846:35 (python3.15t+0x43031e) \n #17 _PyEval_EvalFrame /cpython/./Include/internal/pycore_ceval.h:118:16 (python3.15t+0x429900) \n #18 _PyEval_Vector /cpython/Python/ceval.c:2124:12 (python3.15t+0x429900)\n #19 _PyFunction_Vectorcall /cpython/Objects/call.c (python3.15t+0x21131f) \n #20 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 (python3.15t+0x212e59) \n #21 _PyObject_VectorcallPrepend /cpython/Objects/call.c:855:20 (python3.15t+0x212e59)\n #22 method_vectorcall /cpython/Objects/classobject.c:55:12 (python3.15t+0x21638f) \n #23 _PyVectorcall_Call /cpython/Objects/call.c:273:16 (python3.15t+0x210fab) \n #24 _PyObject_Call /cpython/Objects/call.c:348:16 (python3.15t+0x210fab)\n #25 PyObject_Call /cpython/Objects/call.c:373:12 (python3.15t+0x211015) \n #26 thread_run /cpython/./Modules/_threadmodule.c:388:21 (python3.15t+0x606be2) \n #27 pythread_wrapper /cpython/Python/thread_pthread.h:234:5 (python3.15t+0x536447) \n```\n\n### CPython versions tested on:\n\nPython 3.15.0a8+ free-threading build (heads/main:f93834ff011, Apr 22 2026, 11:41:06)\n\n### Operating systems tested on:\n\nLinux","author":{"url":"https://github.com/Naserume","@type":"Person","name":"Naserume"},"datePublished":"2026-04-22T11:47:53Z","url":"https://github.com/python/cpython/issues/148873"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:75cd4cfb-f5e4-e592-de13-5b42950782b5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BEA6:3DCD28:1773FA9:1F11993:6B020988 |
| html-safe-nonce | 81d7dddebe7b4bc13d53c272670c74e731afa5fe371fb9b4f6068647e7f97ab9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRUE2OjNEQ0QyODoxNzczRkE5OjFGMTE5OTM6NkIwMjA5ODgiLCJ2aXNpdG9yX2lkIjoiNjExMzc2ODQ5NjQ1MzQxMDY0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 746a45c3e64afcb9349fbde27cb3660283342323399b7b5b2694a61ed75e864f |
| hovercard-subject-tag | issue:4308758061 |
| 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/148873/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ece90a8bc30a8c61e61b2064e5159bb722203d825ef99c16d7710521180b0e38/python/cpython/issues/148873 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ece90a8bc30a8c61e61b2064e5159bb722203d825ef99c16d7710521180b0e38/python/cpython/issues/148873 |
| og:image:alt | Bug description: With free-threading, it is possible to read di->di_dict, while it is being written. cpython/Objects/dictobject.c Lines 5611 to 5615 in f93834f static PyObject* dictiter_iternextkey... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Naserume |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width