René's URL Explorer Experiment


Title: gh-75537: Add gc.ensure_disabled() context manager by SakshamKapoor2911 · Pull Request #154999 · python/cpython · GitHub

Open Graph Title: gh-75537: Add gc.ensure_disabled() context manager by SakshamKapoor2911 · Pull Request #154999 · python/cpython

X Title: gh-75537: Add gc.ensure_disabled() context manager by SakshamKapoor2911 · Pull Request #154999 · python/cpython

Description: Fixes: #75537 Summary Add gc.ensure_disabled() — a context manager that temporarily disables the cyclic garbage collector and reliably restores it to its previous state on exit. with gc.ensure_disabled(): ... # GC is disabled during this block Background This feature was originally implemented by @pablogsal in 2018 (PR #4224), merged by @rhettinger, and subsequently reverted (PR #5495/#5496) due to edge cases around GIL release, debug build assertions, and threading concerns during the 3.7 beta window. The modern CPython C API (PyGC_Disable() returns the old state) resolves the key state-tracking issue. The implementation: Uses PyGC_Disable() (returns old state) for atomic state save/restore Runs entirely under the GIL — no threading races Handles nesting: each level saves and restores its own state Properly handles the "already disabled" case: GC stays disabled Tests Four new tests in Lib/test/test_gc.py (GCTogglingTests): test_ensure_disabled, test_ensure_disabled_nesting, test_ensure_disabled_already_disabled, test_ensure_disabled_exception Existing test suite: 59 tests pass, 0 regressions. Issue: gh-75537

Open Graph Description: Fixes: #75537 Summary Add gc.ensure_disabled() — a context manager that temporarily disables the cyclic garbage collector and reliably restores it to its previous state on exit. with gc.ensure_disa...

X Description: Fixes: #75537 Summary Add gc.ensure_disabled() — a context manager that temporarily disables the cyclic garbage collector and reliably restores it to its previous state on exit. with gc.ensure_disa...

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

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:54560ff6-6a59-4cf9-2e3f-74bb654615c9
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE9D0:4BB79:3CC80D1:4D94F71:6B021827
html-safe-nonce431153c241962e6a6b62d1ee546e345f50260c067039648f953b2c560c6bd8e2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOUQwOjRCQjc5OjNDQzgwRDE6NEQ5NEY3MTo2QjAyMTgyNyIsInZpc2l0b3JfaWQiOiI2NTE1MDIyODYyMTY2OTIzMzAzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac0d5e39643215439bb68f7b316a98f26432f6f54d5796408cbfeea61fdfe88ed9
hovercard-subject-tagpull_request:4178913206
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/154999/files
twitter:imagehttps://avatars.githubusercontent.com/u/124176804?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/124176804?s=400&v=4
og:image:altFixes: #75537 Summary Add gc.ensure_disabled() — a context manager that temporarily disables the cyclic garbage collector and reliably restores it to its previous state on exit. with gc.ensure_disa...
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/154999/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F154999%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%2F154999%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/154999/files
Reloadhttps://github.com/python/cpython/pull/154999/files
Reloadhttps://github.com/python/cpython/pull/154999/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
SakshamKapoor2911https://github.com/SakshamKapoor2911
python:mainhttps://github.com/python/cpython/tree/main
SakshamKapoor2911:fix/pr75537-gc-ensure-disabledhttps://github.com/SakshamKapoor2911/cpython/tree/fix/pr75537-gc-ensure-disabled
Conversation 17 https://github.com/python/cpython/pull/154999
Commits 5 https://github.com/python/cpython/pull/154999/commits
Checks 53 https://github.com/python/cpython/pull/154999/checks
Files changed https://github.com/python/cpython/pull/154999/files
Please reload this pagehttps://github.com/python/cpython/pull/154999/files
gh-75537: Add gc.ensure_disabled() context manager https://github.com/python/cpython/pull/154999/files#top
Show all changes 5 commits https://github.com/python/cpython/pull/154999/files
b527c01 gh-75537: Add gc.ensure_disabled() context manager SakshamKapoor2911 Jul 31, 2026 https://github.com/python/cpython/pull/154999/commits/b527c010bf3b77e0f77c7779f931989f5228ae98
83d9729 Add doc and NEWS for gc.ensure_disabled() SakshamKapoor2911 Jul 31, 2026 https://github.com/python/cpython/pull/154999/commits/83d9729482ecdc6a0eb5325fe36f9c06daf3f480
cab16ea Fix NEWS entry filename for blurb format SakshamKapoor2911 Jul 31, 2026 https://github.com/python/cpython/pull/154999/commits/cab16ea1ad315111773bca64c49d066b4fe43bfc
60631ff Remove duplicate enable in __exit__ (dead code after Py_RETURN_NONE) SakshamKapoor2911 Jul 31, 2026 https://github.com/python/cpython/pull/154999/commits/60631ff2631391b9438db5af3b74d474fe2f3087
5a55da3 Remove issue reference from NEWS entry (blurb handles it from filename) SakshamKapoor2911 Jul 31, 2026 https://github.com/python/cpython/pull/154999/commits/5a55da353864099747515712a68abbcf833b3c9a
Clear filters https://github.com/python/cpython/pull/154999/files
Please reload this pagehttps://github.com/python/cpython/pull/154999/files
Please reload this pagehttps://github.com/python/cpython/pull/154999/files
gc.rst https://github.com/python/cpython/pull/154999/files#diff-05935c597d9a54198ea38912d661147c8b1a0091df37848a709b599c462098fa
test_gc.py https://github.com/python/cpython/pull/154999/files#diff-9d9e863bd2a456b669ec9600be793699e861340d91d7c417a8a5b5b8cfbd09a7
2026-07-31-15-35-00.gh-issue-75537.852b0b.rst https://github.com/python/cpython/pull/154999/files#diff-4b41a13f0c4a69c3ae91c0040a1d5556f7f83d6795709843c76c998965e5757f
gcmodule.c https://github.com/python/cpython/pull/154999/files#diff-3ba495fac5f4cc4a582187117515f3177ab91823c65a59af962fe180e06d9e77
globals-to-fix.tsv https://github.com/python/cpython/pull/154999/files#diff-8d1e9a0d5771dfc3a628047509e2d4a1027327bd89392e5a3ec5fbd3d08cfa19
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L479
Doc/library/gc.rsthttps://github.com/python/cpython/pull/154999/files#diff-05935c597d9a54198ea38912d661147c8b1a0091df37848a709b599c462098fa
View file https://github.com/SakshamKapoor2911/cpython/blob/5a55da353864099747515712a68abbcf833b3c9a/Doc/library/gc.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154999/{{ revealButtonHref }}
https://github.com/python/cpython/pull/154999/files#diff-05935c597d9a54198ea38912d661147c8b1a0091df37848a709b599c462098fa
https://github.com/python/cpython/pull/154999/files#diff-05935c597d9a54198ea38912d661147c8b1a0091df37848a709b599c462098fa
Lib/test/test_gc.pyhttps://github.com/python/cpython/pull/154999/files#diff-9d9e863bd2a456b669ec9600be793699e861340d91d7c417a8a5b5b8cfbd09a7
View file https://github.com/SakshamKapoor2911/cpython/blob/5a55da353864099747515712a68abbcf833b3c9a/Lib/test/test_gc.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154999/{{ revealButtonHref }}
https://github.com/python/cpython/pull/154999/files#diff-9d9e863bd2a456b669ec9600be793699e861340d91d7c417a8a5b5b8cfbd09a7
https://github.com/python/cpython/pull/154999/files#diff-9d9e863bd2a456b669ec9600be793699e861340d91d7c417a8a5b5b8cfbd09a7
Misc/NEWS.d/next/Library/2026-07-31-15-35-00.gh-issue-75537.852b0b.rsthttps://github.com/python/cpython/pull/154999/files#diff-4b41a13f0c4a69c3ae91c0040a1d5556f7f83d6795709843c76c998965e5757f
View file https://github.com/SakshamKapoor2911/cpython/blob/5a55da353864099747515712a68abbcf833b3c9a/Misc/NEWS.d/next/Library/2026-07-31-15-35-00.gh-issue-75537.852b0b.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154999/{{ revealButtonHref }}
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L478
Modules/gcmodule.chttps://github.com/python/cpython/pull/154999/files#diff-3ba495fac5f4cc4a582187117515f3177ab91823c65a59af962fe180e06d9e77
View file https://github.com/SakshamKapoor2911/cpython/blob/5a55da353864099747515712a68abbcf833b3c9a/Modules/gcmodule.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154999/{{ revealButtonHref }}
https://github.com/python/cpython/pull/154999/files#diff-3ba495fac5f4cc4a582187117515f3177ab91823c65a59af962fe180e06d9e77
Please reload this pagehttps://github.com/python/cpython/pull/154999/files
Please reload this pagehttps://github.com/python/cpython/pull/154999/files
maurycyhttps://github.com/maurycy
Jul 31, 2026https://github.com/python/cpython/pull/154999/files#r3691897994
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/154999/files
SakshamKapoor2911https://github.com/SakshamKapoor2911
Jul 31, 2026https://github.com/python/cpython/pull/154999/files#r3691975248
Please reload this pagehttps://github.com/python/cpython/pull/154999/files
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/154999/files
SakshamKapoor2911https://github.com/SakshamKapoor2911
Jul 31, 2026https://github.com/python/cpython/pull/154999/files#r3692117479
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
@maurycyhttps://github.com/maurycy
Please reload this pagehttps://github.com/python/cpython/pull/154999/files
https://github.com/python/cpython/pull/154999/files#diff-3ba495fac5f4cc4a582187117515f3177ab91823c65a59af962fe180e06d9e77
https://github.com/python/cpython/pull/154999/files#diff-3ba495fac5f4cc4a582187117515f3177ab91823c65a59af962fe180e06d9e77
https://github.com/python/cpython/pull/154999/files#diff-3ba495fac5f4cc4a582187117515f3177ab91823c65a59af962fe180e06d9e77
https://github.com/python/cpython/pull/154999/files#diff-3ba495fac5f4cc4a582187117515f3177ab91823c65a59af962fe180e06d9e77
https://github.com/python/cpython/pull/154999/files#diff-3ba495fac5f4cc4a582187117515f3177ab91823c65a59af962fe180e06d9e77
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L129
Tools/c-analyzer/cpython/globals-to-fix.tsvhttps://github.com/python/cpython/pull/154999/files#diff-8d1e9a0d5771dfc3a628047509e2d4a1027327bd89392e5a3ec5fbd3d08cfa19
View file https://github.com/SakshamKapoor2911/cpython/blob/5a55da353864099747515712a68abbcf833b3c9a/Tools/c-analyzer/cpython/globals-to-fix.tsv
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154999/{{ revealButtonHref }}
https://github.com/python/cpython/pull/154999/files#diff-8d1e9a0d5771dfc3a628047509e2d4a1027327bd89392e5a3ec5fbd3d08cfa19
Please reload this pagehttps://github.com/python/cpython/pull/154999/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.