René's URL Explorer Experiment


Title: Add a private API to defer automatic garbage collection · Issue #153946 · python/cpython · GitHub

Open Graph Title: Add a private API to defer automatic garbage collection · Issue #153946 · python/cpython

X Title: Add a private API to defer automatic garbage collection · Issue #153946 · python/cpython

Description: I would like to propose a private API that allows CPython internals to defer automatic garbage collection on the current thread without changing the interpreter-visible GC state. Some CPython internals build large object graphs in a burs...

Open Graph Description: I would like to propose a private API that allows CPython internals to defer automatic garbage collection on the current thread without changing the interpreter-visible GC state. Some CPython inter...

X Description: I would like to propose a private API that allows CPython internals to defer automatic garbage collection on the current thread without changing the interpreter-visible GC state. Some CPython inter...

Opengraph URL: https://github.com/python/cpython/issues/153946

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add a private API to defer automatic garbage collection","articleBody":"I would like to propose a private API that allows CPython internals to defer automatic garbage collection on the current thread without changing the interpreter-visible GC state.\n\nSome CPython internals build large object graphs in a burst, where a collection triggered halfway through cannot reclaim anything from that operation and only traverses a half-built graph. Using `PyGC_Disable()` for this changes interpreter-wide state. Saving and restoring that state is racy in the free-threaded build, and it can also be observed or changed by user code in the GIL build.\n\nWhat we want is something approximately like:\n\n```c\n_PyGC_DeferAutomaticCollection(tstate);\n/* Build a large object graph. */\n_PyGC_ResumeAutomaticCollection(tstate);\n```\n\nThis would be a private CPython API. It should be per-thread and nestable, keep allocation counters running, leave `gc.isenabled()` unchanged, and defer only automatic collection. Leaving the outermost scope would schedule a collection if one became due.\n\nI think there are many possible cases in the stdlib and core that can benefit from this, and we currently do not have a safe tool for them. This can be implemented with a small nesting counter in `_PyThreadStateImpl`, checked by the allocation paths and `_Py_RunGC()`. This would allow these optimizations without changing user-visible GC state or introducing cross-thread races.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154188\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/pablogsal","@type":"Person","name":"pablogsal"},"datePublished":"2026-07-18T12:58:53Z","url":"https://github.com/python/cpython/issues/153946"}

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/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:2cf973cf-a3a3-aac0-d150-4b8a25217adb
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9652:19AA62:3CE12A6:4D385D1:6B020875
html-safe-nonce721e1ddc34f140f107cb56fadb92a562fb933199456ea07942ca53f658eed196
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NjUyOjE5QUE2MjozQ0UxMkE2OjREMzg1RDE6NkIwMjA4NzUiLCJ2aXNpdG9yX2lkIjoiMTExMzc4MzY3NzA0Njg4NDQ2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac37c4aaa5e02ae48c5772b22d5b7394e782978c1736a47419d71a3e76ebf5b458
hovercard-subject-tagissue:4918351231
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/153946/issue_layout
twitter:imagehttps://opengraph.githubassets.com/513658bd9a28d7a4e89beeae75f16e4ee613b9585f06c6271a838d1138ec065e/python/cpython/issues/153946
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/513658bd9a28d7a4e89beeae75f16e4ee613b9585f06c6271a838d1138ec065e/python/cpython/issues/153946
og:image:altI would like to propose a private API that allows CPython internals to defer automatic garbage collection on the current thread without changing the interpreter-visible GC state. Some CPython inter...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamepablogsal
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
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
disable-turbofalse
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
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/153946#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F153946
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%2Fissues%2F153946
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/153946
Reloadhttps://github.com/python/cpython/issues/153946
Reloadhttps://github.com/python/cpython/issues/153946
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
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/153946
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/153946
Add a private API to defer automatic garbage collectionhttps://github.com/python/cpython/issues/153946#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/pablogsal
pablogsalhttps://github.com/pablogsal
on Jul 18, 2026https://github.com/python/cpython/issues/153946#issue-4918351231
gh-153946: Add API to defer automatic garbage collection #154188https://github.com/python/cpython/pull/154188
https://github.com/pablogsal
pablogsalhttps://github.com/pablogsal
on Jul 18, 2026https://github.com/python/cpython/issues/153946#issuecomment-5011384944
@naschemehttps://github.com/nascheme
picnixzhttps://github.com/picnixz
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
on Jul 18, 2026https://github.com/python/cpython/issues/153946#event-28159820379
https://github.com/maurycy
maurycyhttps://github.com/maurycy
on Jul 18, 2026https://github.com/python/cpython/issues/153946#issuecomment-5011613634
#153583https://github.com/python/cpython/pull/153583
cpython/Modules/_posixsubprocess.chttps://github.com/python/cpython/blob/1b9fe5c7226eccc8b269a7443148033080399f43/Modules/_posixsubprocess.c#L1063-L1067
1b9fe5chttps://github.com/python/cpython/commit/1b9fe5c7226eccc8b269a7443148033080399f43
https://learn.microsoft.com/en-us/dotnet/api/system.gc.trystartnogcregion?view=net-10.0https://learn.microsoft.com/en-us/dotnet/api/system.gc.trystartnogcregion?view=net-10.0
@sergey-miryanovhttps://github.com/sergey-miryanov
https://github.com/pablogsal
pablogsalhttps://github.com/pablogsal
on Jul 18, 2026https://github.com/python/cpython/issues/153946#issuecomment-5011785141
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Jul 18, 2026https://github.com/python/cpython/issues/153946#issuecomment-5012500663
https://github.com/nascheme
naschemehttps://github.com/nascheme
on Jul 18, 2026https://github.com/python/cpython/issues/153946#issuecomment-5012546610
https://github.com/maurycy
maurycyhttps://github.com/maurycy
on Jul 18, 2026https://github.com/python/cpython/issues/153946#issuecomment-5012653358
#153583https://github.com/python/cpython/pull/153583
https://github.com/sergey-miryanov
sergey-miryanovhttps://github.com/sergey-miryanov
on Jul 18, 2026https://github.com/python/cpython/issues/153946#issuecomment-5012660198
https://github.com/sergey-miryanov
sergey-miryanovhttps://github.com/sergey-miryanov
on Jul 18, 2026https://github.com/python/cpython/issues/153946#issuecomment-5012666690
#139951https://github.com/python/cpython/issues/139951
pablogsalhttps://github.com/pablogsal
on Jul 19, 2026https://github.com/python/cpython/issues/153946#event-28185980259
pythongh-153946: Refine automatic GC deferralhttps://github.com/pablogsal/cpython/commit/ea0af2ffa0f622688d3b241d0f4a11ebdc6f3150
pythongh-153946https://github.com/python/cpython/issues/153946
ea0af2fhttps://github.com/pablogsal/cpython/commit/ea0af2ffa0f622688d3b241d0f4a11ebdc6f3150
pythongh-153946: Fix NEWS entry filenamehttps://github.com/pablogsal/cpython/commit/fe0cc2b70132d3fd12ad9c8bf07404e462da8aca
pythongh-153946https://github.com/python/cpython/issues/153946
fe0cc2bhttps://github.com/pablogsal/cpython/commit/fe0cc2b70132d3fd12ad9c8bf07404e462da8aca
https://github.com/sergey-miryanov
sergey-miryanovhttps://github.com/sergey-miryanov
on Jul 31, 2026https://github.com/python/cpython/issues/153946#issuecomment-5144665263
#154999https://github.com/python/cpython/pull/154999
https://github.com/SakshamKapoor2911
SakshamKapoor2911https://github.com/SakshamKapoor2911
on Jul 31, 2026https://github.com/python/cpython/issues/153946#issuecomment-5144722772
#154999https://github.com/python/cpython/pull/154999
pablogsalhttps://github.com/pablogsal
on Aug 25, 2026https://github.com/python/cpython/issues/153946#event-30012807179
pythongh-153946: Defer automatic GC in object graph buildershttps://github.com/pablogsal/cpython/commit/c9173ae74b28548ff388e01e49ad6d4d487ad820
pythongh-153946https://github.com/python/cpython/issues/153946
c9173aehttps://github.com/pablogsal/cpython/commit/c9173ae74b28548ff388e01e49ad6d4d487ad820
pythongh-153946: Refine automatic GC deferralhttps://github.com/pablogsal/cpython/commit/9319acdf1a2c0e43d6530b58d06172937a2cd79f
pythongh-153946https://github.com/python/cpython/issues/153946
9319acdhttps://github.com/pablogsal/cpython/commit/9319acdf1a2c0e43d6530b58d06172937a2cd79f
pythongh-153946: Fix NEWS entry filenamehttps://github.com/pablogsal/cpython/commit/920df6a23179763e9f10bc9545904310b5399c72
pythongh-153946https://github.com/python/cpython/issues/153946
920df6ahttps://github.com/pablogsal/cpython/commit/920df6a23179763e9f10bc9545904310b5399c72
pythongh-153946: Reset automatic GC deferral after forkhttps://github.com/pablogsal/cpython/commit/35cfb621f8d391d3912ae275e62f324006071029
pythongh-153946https://github.com/python/cpython/issues/153946
35cfb62https://github.com/pablogsal/cpython/commit/35cfb621f8d391d3912ae275e62f324006071029
pythongh-153946: Suppress expected fork warning in testhttps://github.com/pablogsal/cpython/commit/488c75b3c5d0cc05ee904f3218f7216f83cb1872
pythongh-153946https://github.com/python/cpython/issues/153946
488c75bhttps://github.com/pablogsal/cpython/commit/488c75b3c5d0cc05ee904f3218f7216f83cb1872
pythongh-153946: Preserve active GC deferrals after forkhttps://github.com/pablogsal/cpython/commit/c723f523005070cfaa184c7916242434fd40ff5b
pythongh-153946https://github.com/python/cpython/issues/153946
c723f52https://github.com/pablogsal/cpython/commit/c723f523005070cfaa184c7916242434fd40ff5b
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/153946
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/153946
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
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.