Title: Sequence iterator thread-safety · Issue #120496 · python/cpython · GitHub
Open Graph Title: Sequence iterator thread-safety · Issue #120496 · python/cpython
X Title: Sequence iterator thread-safety · Issue #120496 · python/cpython
Description: Bug report Bug description: Sequence iterators are not thread-safe under the free-threaded build. They'll sometimes be accessed with the same index. Here is a minimal repro: import concurrent.futures N = 10000 for _ in range(100): it = i...
Open Graph Description: Bug report Bug description: Sequence iterators are not thread-safe under the free-threaded build. They'll sometimes be accessed with the same index. Here is a minimal repro: import concurrent.futur...
X Description: Bug report Bug description: Sequence iterators are not thread-safe under the free-threaded build. They'll sometimes be accessed with the same index. Here is a minimal repro: import concurrent.f...
Opengraph URL: https://github.com/python/cpython/issues/120496
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Sequence iterator thread-safety","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nSequence iterators are not thread-safe under the free-threaded build. They'll sometimes be accessed with the same index.\r\n\r\nHere is a minimal repro:\r\n```python\r\nimport concurrent.futures\r\n\r\nN = 10000\r\n\r\nfor _ in range(100):\r\n it = iter(range(N))\r\n\r\n with concurrent.futures.ThreadPoolExecutor() as executor:\r\n data = set(executor.map(lambda _: next(it), range(N)))\r\n\r\n assert len(data) == N, f\"Expected {N} distinct elements, got {len(data)}\"\r\n```\r\n\r\nI also tested it with `list` and `dict` iterators as well as a custom class implementing `__getitem__`.\r\n\r\n\r\n### CPython versions tested on:\r\n\r\nCPython main branch\r\n\r\n### Operating systems tested on:\r\n\r\nLinux, macOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-120534\n* gh-120540\n* gh-120591\n* gh-120685\n* gh-120706\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/rostan-t","@type":"Person","name":"rostan-t"},"datePublished":"2024-06-14T12:01:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/120496/cpython/issues/120496"}
| 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:824cd927-c081-8dba-54e3-367318815124 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA9C:29BF10:1A3AE2:21D6B4:696B6208 |
| html-safe-nonce | 547efe21dc99b588f14bb4dbf522381b6ae6a8f632e702f8686e2f59acfc322a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTlDOjI5QkYxMDoxQTNBRTI6MjFENkI0OjY5NkI2MjA4IiwidmlzaXRvcl9pZCI6IjMxNTQxMDIzMjkwMDIzODU5MjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 368029a09ccbcef6a1ce3b4c327a336c2eb675d47ae624fa550bbdbf16889123 |
| hovercard-subject-tag | issue:2353220184 |
| 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/120496/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2b28caa4c0d7141598d018c951527b319b5a883a55dca338385ce2695c11d3a9/python/cpython/issues/120496 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2b28caa4c0d7141598d018c951527b319b5a883a55dca338385ce2695c11d3a9/python/cpython/issues/120496 |
| og:image:alt | Bug report Bug description: Sequence iterators are not thread-safe under the free-threaded build. They'll sometimes be accessed with the same index. Here is a minimal repro: import concurrent.futur... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rostan-t |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width