René's URL Explorer Experiment


Title: gh-144356: Make set iterator `__length_hint__` and `iternext` race-safe under no-gil by hyongtao-code · Pull Request #144357 · python/cpython · GitHub

Open Graph Title: gh-144356: Make set iterator `__length_hint__` and `iternext` race-safe under no-gil by hyongtao-code · Pull Request #144357 · python/cpython

X Title: gh-144356: Make set iterator `__length_hint__` and `iternext` race-safe under no-gil by hyongtao-code · Pull Request #144357 · python/cpython

Description: Long log: In free-threaded builds, setiter_len() and setiter_iternext() could race with concurrent set mutation and iterator exhaustion. We now serialize operations on the iterator itself (and keep the set stable) using a critical section, and ensure the iterator’s exhaustion state is handled consistently. The non-free-threaded build keeps the existing semantics. Add free-threading-style concurrency tests (similar to the itertools FT tests) to exercise __length_hint__ and iternext exhaustion under concurrent execution. setiter_len() was reading so->used without atomic access while concurrent mutations update it atomically under Py_GIL_DISABLED. In free-threaded builds, setiter_len() could race with concurrent set mutation and iterator exhaustion. Use an atomic load for so->used to avoid a data race. This preserves the existing semantics of __length_hint__ while making the access thread-safe. Signed-off-by: Yongtao Huang yongtaoh2022@gmail.com Issue: gh-144356

Open Graph Description: Long log: In free-threaded builds, setiter_len() and setiter_iternext() could race with concurrent set mutation and iterator exhaustion. We now serialize operations on the iterator itself (and keep...

X Description: Long log: In free-threaded builds, setiter_len() and setiter_iternext() could race with concurrent set mutation and iterator exhaustion. We now serialize operations on the iterator itself (and keep...

Opengraph URL: https://github.com/python/cpython/pull/144357

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:746a7b46-87d9-9a37-bf40-f5f1c91b7bed
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE036:D1D28:17B77A2:1F715B5:6B020C35
html-safe-nonce0895d943809509ec1dcb1e89f8bbe251b92e20c55b85f55441869c41170caee2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDM2OkQxRDI4OjE3Qjc3QTI6MUY3MTVCNTo2QjAyMEMzNSIsInZpc2l0b3JfaWQiOiI0NjcxMTY2MTI4OTUxNzkwNjQ1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmaca2c223904d0918a077a507d91b03546020449bf55e534ab9a3165a99b5d522d7
hovercard-subject-tagpull_request:3229975946
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/144357/files
twitter:imagehttps://avatars.githubusercontent.com/u/99629139?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/99629139?s=400&v=4
og:image:altLong log: In free-threaded builds, setiter_len() and setiter_iternext() could race with concurrent set mutation and iterator exhaustion. We now serialize operations on the iterator itself (and keep...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/144357/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F144357%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F144357%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/144357/files
Reloadhttps://github.com/python/cpython/pull/144357/files
Reloadhttps://github.com/python/cpython/pull/144357/files
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
hyongtao-codehttps://github.com/hyongtao-code
python:mainhttps://github.com/python/cpython/tree/main
hyongtao-code:fix-data-racehttps://github.com/hyongtao-code/cpython/tree/fix-data-race
Conversation 50 https://github.com/python/cpython/pull/144357
Commits 24 https://github.com/python/cpython/pull/144357/commits
Checks 23 https://github.com/python/cpython/pull/144357/checks
Files changed https://github.com/python/cpython/pull/144357/files
Please reload this pagehttps://github.com/python/cpython/pull/144357/files
gh-144356: Make set iterator __length_hint__ and iternext race-safe under no-gil https://github.com/python/cpython/pull/144357/files#top
Show all changes 24 commits https://github.com/python/cpython/pull/144357/files
47d75fe Fix data race in setiter_len() under no-gil hyongtao-code Jan 31, 2026 https://github.com/python/cpython/pull/144357/commits/47d75fee96b929343e8713e98e3ce9400b34a15c
3e3785c Add test case hyongtao-code Jan 31, 2026 https://github.com/python/cpython/pull/144357/commits/3e3785cb6cde129bb19b6db8278bae4351f45be9
229ced3 📜🤖 Added by blurb_it. blurb-it[bot] Jan 31, 2026 https://github.com/python/cpython/pull/144357/commits/229ced3b1c5be4e1cbeb4db70b7a5dd8645df955
cdcf88a Resovle comments hyongtao-code Feb 1, 2026 https://github.com/python/cpython/pull/144357/commits/cdcf88ad474f675f8bc4fbc6956aca71e4667fba
21f1478 Update test case: used_race and exhaust_race hyongtao-code Feb 1, 2026 https://github.com/python/cpython/pull/144357/commits/21f1478423e09eee0ea7c082d46fe5d6291e2cc3
a18c698 Add test case hyongtao-code Feb 6, 2026 https://github.com/python/cpython/pull/144357/commits/a18c6989439e6b0d69ddc7300eb5df3eea8c7baf
79b5fbc Try to address the comments hyongtao-code Feb 6, 2026 https://github.com/python/cpython/pull/144357/commits/79b5fbc0c3d0cd3f959ecf212af225511b7935d0
6ac15e0 Post fix hyongtao-code Feb 6, 2026 https://github.com/python/cpython/pull/144357/commits/6ac15e06a61ec4411c853f210e4785a293ea618c
3222eef Address comments hyongtao-code Feb 8, 2026 https://github.com/python/cpython/pull/144357/commits/3222eef47fe2a034b035458957772b980fd58a75
7fb39bc Post fix hyongtao-code Feb 8, 2026 https://github.com/python/cpython/pull/144357/commits/7fb39bc6ed261316dff5fc6a2a1d11b3c4168233
78241a8 Update Lib/test/test_free_threading/test_set.py hyongtao-code Feb 9, 2026 https://github.com/python/cpython/pull/144357/commits/78241a862bd12a42ab369790ad8bedbe2fc2fc41
52285a2 Revert "Update Lib/test/test_free_threading/test_set.py" hyongtao-code Feb 9, 2026 https://github.com/python/cpython/pull/144357/commits/52285a27f79c1ca47b62fc8db8aaf317065cdb25
c9ece31 Address comments hyongtao-code Feb 9, 2026 https://github.com/python/cpython/pull/144357/commits/c9ece317157c650c44b744128608e66b31ef8acf
e41e852 Enhance the test case as test_itertools.py hyongtao-code Feb 10, 2026 https://github.com/python/cpython/pull/144357/commits/e41e852002dbec727ad6d1a81e3dfd87725f0aef
b32b5ec Update NEWS hyongtao-code Feb 10, 2026 https://github.com/python/cpython/pull/144357/commits/b32b5ec7ec21a9386dadcc61d6529175d3df607b
d14856c Address comment hyongtao-code Feb 10, 2026 https://github.com/python/cpython/pull/144357/commits/d14856c7fe1f670ec7042ae43018825a68c7ada2
2a512a8 Address comments hyongtao-code Feb 10, 2026 https://github.com/python/cpython/pull/144357/commits/2a512a8fc72d95b4986cb16b7698155585d50cfb
1ce898a Update test cases hyongtao-code Feb 11, 2026 https://github.com/python/cpython/pull/144357/commits/1ce898a7548e456f6fff979b083468822d477c3d
c110ddd Address comments: unused code hyongtao-code Feb 13, 2026 https://github.com/python/cpython/pull/144357/commits/c110dddf7d12ddf18ccef9b07d8b7e924db62283
6120aef Update Lib/test/test_free_threading/test_set.py hyongtao-code Feb 13, 2026 https://github.com/python/cpython/pull/144357/commits/6120aefd41b3810b3ce23d7e8ab84f1039e0c200
afea804 Update Objects/setobject.c hyongtao-code Feb 13, 2026 https://github.com/python/cpython/pull/144357/commits/afea804ea97500f41d565e9fc7729a8c3181e9b8
dc4eaa6 Remove empyt line hyongtao-code Feb 14, 2026 https://github.com/python/cpython/pull/144357/commits/dc4eaa6f798f768ea7ebdf4beba971ebbd2b3f1e
b2ef863 Address comments hyongtao-code Mar 11, 2026 https://github.com/python/cpython/pull/144357/commits/b2ef863f605398c4457d1974d4f1f24ca5eb0327
8e2af8b Merge branch 'main' into fix-data-race hyongtao-code May 19, 2026 https://github.com/python/cpython/pull/144357/commits/8e2af8b0c308ba2d4aaa945e1bddb1f02f4a0a27
Clear filters https://github.com/python/cpython/pull/144357/files
Please reload this pagehttps://github.com/python/cpython/pull/144357/files
Please reload this pagehttps://github.com/python/cpython/pull/144357/files
test_set.py https://github.com/python/cpython/pull/144357/files#diff-b994f343b9e103f63fa93441746390c7d4224a671119c12cab4b85fb151c4af4
2026-01-31-03-40-28.gh-issue-144356.otfq_X.rst https://github.com/python/cpython/pull/144357/files#diff-64114e5a5083f8839987abfd2d16eeb22057c7fa3f8e1cdaf9711ca67592b73d
setobject.c https://github.com/python/cpython/pull/144357/files#diff-537c6127e75079330edcb3775b0b9c2e4aeb34530dfe224ef2c96c3acb42111f
Lib/test/test_free_threading/test_set.pyhttps://github.com/python/cpython/pull/144357/files#diff-b994f343b9e103f63fa93441746390c7d4224a671119c12cab4b85fb151c4af4
View file https://github.com/python/cpython/blob/8e2af8b0c308ba2d4aaa945e1bddb1f02f4a0a27/Lib/test/test_free_threading/test_set.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/144357/{{ revealButtonHref }}
https://github.com/python/cpython/pull/144357/files#diff-b994f343b9e103f63fa93441746390c7d4224a671119c12cab4b85fb151c4af4
https://github.com/python/cpython/pull/144357/files#diff-b994f343b9e103f63fa93441746390c7d4224a671119c12cab4b85fb151c4af4
Misc/NEWS.d/next/Core_and_Builtins/2026-01-31-03-40-28.gh-issue-144356.otfq_X.rsthttps://github.com/python/cpython/pull/144357/files#diff-64114e5a5083f8839987abfd2d16eeb22057c7fa3f8e1cdaf9711ca67592b73d
View file https://github.com/python/cpython/blob/8e2af8b0c308ba2d4aaa945e1bddb1f02f4a0a27/Misc/NEWS.d/next/Core_and_Builtins/2026-01-31-03-40-28.gh-issue-144356.otfq_X.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/144357/{{ revealButtonHref }}
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L216
Objects/setobject.chttps://github.com/python/cpython/pull/144357/files#diff-537c6127e75079330edcb3775b0b9c2e4aeb34530dfe224ef2c96c3acb42111f
View file https://github.com/python/cpython/blob/8e2af8b0c308ba2d4aaa945e1bddb1f02f4a0a27/Objects/setobject.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/144357/{{ revealButtonHref }}
https://github.com/python/cpython/pull/144357/files#diff-537c6127e75079330edcb3775b0b9c2e4aeb34530dfe224ef2c96c3acb42111f
https://github.com/python/cpython/pull/144357/files#diff-537c6127e75079330edcb3775b0b9c2e4aeb34530dfe224ef2c96c3acb42111f
https://github.com/python/cpython/pull/144357/files#diff-537c6127e75079330edcb3775b0b9c2e4aeb34530dfe224ef2c96c3acb42111f
https://github.com/python/cpython/pull/144357/files#diff-537c6127e75079330edcb3775b0b9c2e4aeb34530dfe224ef2c96c3acb42111f
eendebakpthttps://github.com/eendebakpt
Feb 10, 2026https://github.com/python/cpython/pull/144357/files#r2789927299
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/144357/files
hyongtao-codehttps://github.com/hyongtao-code
Feb 13, 2026https://github.com/python/cpython/pull/144357/files#r2803696896
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/144357/files
https://github.com/python/cpython/pull/144357/files#diff-537c6127e75079330edcb3775b0b9c2e4aeb34530dfe224ef2c96c3acb42111f
Please reload this pagehttps://github.com/python/cpython/pull/144357/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.