René's URL Explorer Experiment


Title: gh-90549: Fix leak of global named resources using multiprocessing spawn by jxdabc · Pull Request #30617 · python/cpython · GitHub

Open Graph Title: gh-90549: Fix leak of global named resources using multiprocessing spawn by jxdabc · Pull Request #30617 · python/cpython

X Title: gh-90549: Fix leak of global named resources using multiprocessing spawn by jxdabc · Pull Request #30617 · python/cpython

Description: Repo is the standard tool that Google uses to build Android, Chrome OS, Chromium, etc, written in Python. Many Repo users have encountered resource leak warnings with Python 3.9. https://bugs.chromium.org/p/gerrit/issues/detail?id=14934&q=component:repo&can=5 I did some work and found that the problem is not caused by the code of Repo, but a bug of the Python library, multiprocess. To make it simple, the Python script below leaks named resource even when exiting normally. (And be unlinked by resource_tracker with a warning. ) import multiprocessing as mp global_resource = mp.Semaphore() def submain(): pass if __name__ == '__main__': p = mp.Process(target=submain) p.start() p.join() Tested on macOS with Python 3.9.7 python test.py resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown. This bug will 100% reproduce when then main module uses named resources as global variables and uses spawn context, which is the case of Repo on macOS. This is caused by multiprocess::BaseProcess::_bootstrap. When a new process is started with multiprocessing.Process.start() in spawn context. The main module is reloaded in the subprocess (for pickle) in multiprocessing::spawn::_main. Named resources (such as the semaphore above) in the main module resister their _cleanup into multiprocessing::util::_finalizer_registry, which unlink themselves. multiprocess::BaseProcess::_bootstrap then clears _finalizer_registry. When a subprocess is spawned, it is no need to clear util::_finalizer_registry (and no need to call util::_run_after_forkers). Disable clearing _finalizer_registry (and disable call to _run_after_forkers) should fix this bug without breaking anything else. And I uploaded a MR. https://bugs.python.org/issue46391

Open Graph Description: Repo is the standard tool that Google uses to build Android, Chrome OS, Chromium, etc, written in Python. Many Repo users have encountered resource leak warnings with Python 3.9. https://bugs.chrom...

X Description: Repo is the standard tool that Google uses to build Android, Chrome OS, Chromium, etc, written in Python. Many Repo users have encountered resource leak warnings with Python 3.9. https://bugs.chrom...

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

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:d9df228d-1c6a-15c0-4e09-a8a55761eca9
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idB8DE:1860A8:FC5995:15E1073:696A87CB
html-safe-noncee9754511b05c009dae7ebfc3c6fa69360ac97676e689f20a1819ce3f37c33ae8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOERFOjE4NjBBODpGQzU5OTU6MTVFMTA3Mzo2OTZBODdDQiIsInZpc2l0b3JfaWQiOiI0NzQzNzEwOTA1Mzk4MzY0MTA3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacb6e3d29febd927b986fd24b39e32251c51f52b91430a61084a676d8936a81e3a
hovercard-subject-tagpull_request:823715733
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/30617/files
twitter:imagehttps://avatars.githubusercontent.com/u/2919303?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/2919303?s=400&v=4
og:image:altRepo is the standard tool that Google uses to build Android, Chrome OS, Chromium, etc, written in Python. Many Repo users have encountered resource leak warnings with Python 3.9. https://bugs.chrom...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noned2aa6dedd7d97fa651b17c40401f2605f309df5ca5fb659bf0554cf34f1de825
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
releasec1dbca8981c5e3d6a69bce2f1d289e732b86241d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/30617/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F30617%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F30617%2Ffiles
Sign up https://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/30617/files
Reloadhttps://github.com/python/cpython/pull/30617/files
Reloadhttps://github.com/python/cpython/pull/30617/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/30617/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/pull/30617/files
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
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
pitrouhttps://github.com/pitrou
python:mainhttps://github.com/python/cpython/tree/main
jxdabc:fix-issue-46391https://github.com/jxdabc/cpython/tree/fix-issue-46391
Conversation 67 https://github.com/python/cpython/pull/30617
Commits 3 https://github.com/python/cpython/pull/30617/commits
Checks 0 https://github.com/python/cpython/pull/30617/checks
Files changed https://github.com/python/cpython/pull/30617/files
Please reload this pagehttps://github.com/python/cpython/pull/30617/files
gh-90549: Fix leak of global named resources using multiprocessing spawn https://github.com/python/cpython/pull/30617/files#top
Show all changes 3 commits https://github.com/python/cpython/pull/30617/files
f202fff bpo-46391: Library multiprocess leaks named resources. Jan 15, 2022 https://github.com/python/cpython/pull/30617/commits/f202fff5a5a4a8ef1914748f446fc1a34515ea73
f3a947d Improve NEWS wording pitrou Jun 6, 2022 https://github.com/python/cpython/pull/30617/commits/f3a947d80677929ee73b3e17e4e205779d1d97de
7cc22ae update test code and news Jun 7, 2022 https://github.com/python/cpython/pull/30617/commits/7cc22aef34aa303f148b630eca16937d161361d6
Clear filters https://github.com/python/cpython/pull/30617/files
Please reload this pagehttps://github.com/python/cpython/pull/30617/files
Please reload this pagehttps://github.com/python/cpython/pull/30617/files
context.py https://github.com/python/cpython/pull/30617/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
process.py https://github.com/python/cpython/pull/30617/files#diff-95e01a1db1003c313b93ab726870bc6ddaa916f28479bb17fea2331fb8b5ac7f
_test_multiprocessing.py https://github.com/python/cpython/pull/30617/files#diff-c3db62f7c1928499afd71830c22c8bb8f56843a4533cecf69137973d73c489fc
2022-06-07-14-53-46.gh-issue-90549.T4FMKY.rst https://github.com/python/cpython/pull/30617/files#diff-d4b8a715566fddaa03b5d0090953dc8660c6d4e329a8b28614e174a73c306b16
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L519
Lib/multiprocessing/context.pyhttps://github.com/python/cpython/pull/30617/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
View file https://github.com/jxdabc/cpython/blob/7cc22aef34aa303f148b630eca16937d161361d6/Lib/multiprocessing/context.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/30617/{{ revealButtonHref }}
https://github.com/python/cpython/pull/30617/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
Please reload this pagehttps://github.com/python/cpython/pull/30617/files
Please reload this pagehttps://github.com/python/cpython/pull/30617/files
https://github.com/python/cpython/pull/30617/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
https://github.com/python/cpython/pull/30617/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
https://github.com/python/cpython/pull/30617/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
https://github.com/python/cpython/pull/30617/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
https://github.com/python/cpython/pull/30617/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L519
Lib/multiprocessing/process.pyhttps://github.com/python/cpython/pull/30617/files#diff-95e01a1db1003c313b93ab726870bc6ddaa916f28479bb17fea2331fb8b5ac7f
View file https://github.com/jxdabc/cpython/blob/7cc22aef34aa303f148b630eca16937d161361d6/Lib/multiprocessing/process.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/30617/{{ revealButtonHref }}
https://github.com/python/cpython/pull/30617/files#diff-95e01a1db1003c313b93ab726870bc6ddaa916f28479bb17fea2331fb8b5ac7f
https://github.com/python/cpython/pull/30617/files#diff-95e01a1db1003c313b93ab726870bc6ddaa916f28479bb17fea2331fb8b5ac7f
https://github.com/python/cpython/pull/30617/files#diff-95e01a1db1003c313b93ab726870bc6ddaa916f28479bb17fea2331fb8b5ac7f
https://github.com/python/cpython/pull/30617/files#diff-95e01a1db1003c313b93ab726870bc6ddaa916f28479bb17fea2331fb8b5ac7f
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L520
Lib/test/_test_multiprocessing.pyhttps://github.com/python/cpython/pull/30617/files#diff-c3db62f7c1928499afd71830c22c8bb8f56843a4533cecf69137973d73c489fc
View file https://github.com/jxdabc/cpython/blob/7cc22aef34aa303f148b630eca16937d161361d6/Lib/test/_test_multiprocessing.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/30617/{{ revealButtonHref }}
https://github.com/python/cpython/pull/30617/files#diff-c3db62f7c1928499afd71830c22c8bb8f56843a4533cecf69137973d73c489fc
https://github.com/python/cpython/pull/30617/files#diff-c3db62f7c1928499afd71830c22c8bb8f56843a4533cecf69137973d73c489fc
https://github.com/python/cpython/pull/30617/files#diff-c3db62f7c1928499afd71830c22c8bb8f56843a4533cecf69137973d73c489fc
Please reload this pagehttps://github.com/python/cpython/pull/30617/files
https://github.com/python/cpython/pull/30617/files#diff-c3db62f7c1928499afd71830c22c8bb8f56843a4533cecf69137973d73c489fc
Misc/NEWS.d/next/Library/2022-06-07-14-53-46.gh-issue-90549.T4FMKY.rsthttps://github.com/python/cpython/pull/30617/files#diff-d4b8a715566fddaa03b5d0090953dc8660c6d4e329a8b28614e174a73c306b16
View file https://github.com/jxdabc/cpython/blob/7cc22aef34aa303f148b630eca16937d161361d6/Misc/NEWS.d/next/Library/2022-06-07-14-53-46.gh-issue-90549.T4FMKY.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/30617/{{ revealButtonHref }}
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.