René's URL Explorer Experiment


Title: gh-126688: Support Fork Parent and Child With Different Thread ID by ericsnowcurrently · Pull Request #127121 · python/cpython · GitHub

Open Graph Title: gh-126688: Support Fork Parent and Child With Different Thread ID by ericsnowcurrently · Pull Request #127121 · python/cpython

X Title: gh-126688: Support Fork Parent and Child With Different Thread ID by ericsnowcurrently · Pull Request #127121 · python/cpython

Description: gh-126692 took care of one situation where we were assuming the thread ID did not change across fork. However, there is at least one other, in PyOS_AfterFork_Child(). This PR addresses that case along with making the parent's thread ID available to the child. Here's a breakdown: add _PyRuntimeState.os_fork.mutex to allow only one instance of forking to happen at once (in part, to protect the rest of _PyRuntimeState.os_fork) add _PyRuntimeState.os_fork.parent.tid to make the parent's thread ID available to the child add _PyRecursiveMutex_at_fork_reinit(), which makes use of the parent thread ID use _PyRecursiveMutex_at_fork_reinit() in _PyImport_ReInitLock() I've also moved the _PyImport_ReInitLock() call from PyOS_AfterFork_Child() to _PyRuntimeState_ReInitThreads(), to be more consistent about where we reinitialize locks after forking. If there are any objections, I don't mind dropping that part. One motivation I have here is that I'd like to use a _PyRecursiveMutex elsewhere and need to be able to correctly reinitialize after forking. That requires knowing the parent's thread ID, to decide if the forking thread held the lock or not. (This wasn't a problem for the import lock, which is a _PyRecursiveMutex, since we always acquire and hold that lock while forking.) @gpshead, I'd be particularly interested in your thoughts on this. Issue: gh-126688

Open Graph Description: gh-126692 took care of one situation where we were assuming the thread ID did not change across fork. However, there is at least one other, in PyOS_AfterFork_Child(). This PR addresses that case ...

X Description: gh-126692 took care of one situation where we were assuming the thread ID did not change across fork. However, there is at least one other, in PyOS_AfterFork_Child(). This PR addresses that case ...

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

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:bfe8197c-98d9-3b0f-13aa-1fee75dcc8e4
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idBDA4:129889:1135A8F:172D65B:6A594A1A
html-safe-noncee4beda3e4de624f2dfbfa8b5746ace21ededb7da50086e1664347bde87787250
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCREE0OjEyOTg4OToxMTM1QThGOjE3MkQ2NUI6NkE1OTRBMUEiLCJ2aXNpdG9yX2lkIjoiNDI0MzEwNjkzNzc3OTYwMzk5NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac0359e3da3865c5fd3219fdb211d15d3d228fd521624ae32c59373f6520ddfd75
hovercard-subject-tagpull_request:2193325845
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/127121/files
twitter:imagehttps://avatars.githubusercontent.com/u/1152074?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/1152074?s=400&v=4
og:image:altgh-126692 took care of one situation where we were assuming the thread ID did not change across fork. However, there is at least one other, in PyOS_AfterFork_Child(). This PR addresses that case ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None9f801e05b35c85b2d72eae6534d2b1d4c02ba8732fd046450bab31e2f52450ce
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
release49918fc503387d6d65b6bc6ce6f711c14d17bfbd
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/127121/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F127121%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
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
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
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/enterprise/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%2F127121%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/127121/files
Reloadhttps://github.com/python/cpython/pull/127121/files
Reloadhttps://github.com/python/cpython/pull/127121/files
Please reload this pagehttps://github.com/python/cpython/pull/127121/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/127121/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 34.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k 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.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
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 and quality 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
ericsnowcurrentlyhttps://github.com/ericsnowcurrently
python:mainhttps://github.com/python/cpython/tree/main
ericsnowcurrently:preserve-parent-tidhttps://github.com/ericsnowcurrently/cpython/tree/preserve-parent-tid
Conversation 4 https://github.com/python/cpython/pull/127121
Commits 6 https://github.com/python/cpython/pull/127121/commits
Checks 0 https://github.com/python/cpython/pull/127121/checks
Files changed https://github.com/python/cpython/pull/127121/files
Please reload this pagehttps://github.com/python/cpython/pull/127121/files
gh-126688: Support Fork Parent and Child With Different Thread ID https://github.com/python/cpython/pull/127121/files#top
Show all changes 6 commits https://github.com/python/cpython/pull/127121/files
20a9bd6 Hold a global lock while forking. ericsnowcurrently Nov 21, 2024 https://github.com/python/cpython/pull/127121/commits/20a9bd64d0d6c5221f93e54e4dc51d4e1e77bfdb
259e3c6 Keep track of the parent thread ID. ericsnowcurrently Nov 21, 2024 https://github.com/python/cpython/pull/127121/commits/259e3c672acc97a7a023f9123bc721dd5ea7879c
8fbd4fc Update the tstate thread ID if necessary. ericsnowcurrently Nov 21, 2024 https://github.com/python/cpython/pull/127121/commits/8fbd4fc668bca6e1a92e698b8460d34ecb9e40d7
db5271a Add _PyRecursiveMutex_at_fork_reinit(). ericsnowcurrently Nov 21, 2024 https://github.com/python/cpython/pull/127121/commits/db5271aca354960073e95acef02ba5806e40563f
9e015f8 Use _PyRecursiveMutex_at_fork_reinit() in _PyImport_ReInitLock(). ericsnowcurrently Nov 21, 2024 https://github.com/python/cpython/pull/127121/commits/9e015f8dd425a7ebf0ffc4736359ac3ff16762aa
2aad2d5 Call _PyImport_ReInitLock() in _PyRuntimeState_ReInitThreads(). ericsnowcurrently Nov 21, 2024 https://github.com/python/cpython/pull/127121/commits/2aad2d5db78d0e45574b3a571804b79b12154880
Clear filters https://github.com/python/cpython/pull/127121/files
Please reload this pagehttps://github.com/python/cpython/pull/127121/files
Please reload this pagehttps://github.com/python/cpython/pull/127121/files
pycore_import.h https://github.com/python/cpython/pull/127121/files#diff-f0d0635a621a67c4105f6b306ecabc7b6f8e1fe1518ae49baf006c26f71520b5
pycore_lock.h https://github.com/python/cpython/pull/127121/files#diff-c4ea3ba1b986b7045be6c6260113e2b765c497ec9842e5c6c30abe466d1f2c73
pycore_runtime.h https://github.com/python/cpython/pull/127121/files#diff-004269ce4e6ea86068fb11d8ad53fc4321b693e991e9f847b43d0ecf97482862
posixmodule.c https://github.com/python/cpython/pull/127121/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
import.c https://github.com/python/cpython/pull/127121/files#diff-28cfc3e2868980a79d93d2ebdc8747dcb9231f3dd7f2caef96e74107d1ea3bf3
pystate.c https://github.com/python/cpython/pull/127121/files#diff-7ac11e526f79b42d6ea9d3592cb99da46775640c69fa5510f4a6de87cced7141
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L264
Include/internal/pycore_import.hhttps://github.com/python/cpython/pull/127121/files#diff-f0d0635a621a67c4105f6b306ecabc7b6f8e1fe1518ae49baf006c26f71520b5
View file https://github.com/python/cpython/blob/2aad2d5db78d0e45574b3a571804b79b12154880/Include/internal/pycore_import.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/127121/{{ revealButtonHref }}
https://github.com/python/cpython/pull/127121/files#diff-f0d0635a621a67c4105f6b306ecabc7b6f8e1fe1518ae49baf006c26f71520b5
https://github.com/python/cpython/pull/127121/files#diff-f0d0635a621a67c4105f6b306ecabc7b6f8e1fe1518ae49baf006c26f71520b5
https://github.com/python/cpython/pull/127121/files#diff-f0d0635a621a67c4105f6b306ecabc7b6f8e1fe1518ae49baf006c26f71520b5
Include/internal/pycore_lock.hhttps://github.com/python/cpython/pull/127121/files#diff-c4ea3ba1b986b7045be6c6260113e2b765c497ec9842e5c6c30abe466d1f2c73
View file https://github.com/python/cpython/blob/2aad2d5db78d0e45574b3a571804b79b12154880/Include/internal/pycore_lock.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/127121/{{ revealButtonHref }}
https://github.com/python/cpython/pull/127121/files#diff-c4ea3ba1b986b7045be6c6260113e2b765c497ec9842e5c6c30abe466d1f2c73
https://github.com/python/cpython/pull/127121/files#diff-c4ea3ba1b986b7045be6c6260113e2b765c497ec9842e5c6c30abe466d1f2c73
https://github.com/python/cpython/pull/127121/files#diff-c4ea3ba1b986b7045be6c6260113e2b765c497ec9842e5c6c30abe466d1f2c73
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L330
Include/internal/pycore_runtime.hhttps://github.com/python/cpython/pull/127121/files#diff-004269ce4e6ea86068fb11d8ad53fc4321b693e991e9f847b43d0ecf97482862
View file https://github.com/python/cpython/blob/2aad2d5db78d0e45574b3a571804b79b12154880/Include/internal/pycore_runtime.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/127121/{{ revealButtonHref }}
https://github.com/python/cpython/pull/127121/files#diff-004269ce4e6ea86068fb11d8ad53fc4321b693e991e9f847b43d0ecf97482862
https://github.com/python/cpython/pull/127121/files#diff-004269ce4e6ea86068fb11d8ad53fc4321b693e991e9f847b43d0ecf97482862
https://github.com/python/cpython/pull/127121/files#diff-004269ce4e6ea86068fb11d8ad53fc4321b693e991e9f847b43d0ecf97482862
https://github.com/python/cpython/pull/127121/files#diff-004269ce4e6ea86068fb11d8ad53fc4321b693e991e9f847b43d0ecf97482862
Modules/posixmodule.chttps://github.com/python/cpython/pull/127121/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
View file https://github.com/python/cpython/blob/2aad2d5db78d0e45574b3a571804b79b12154880/Modules/posixmodule.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/127121/{{ revealButtonHref }}
https://github.com/python/cpython/pull/127121/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
https://github.com/python/cpython/pull/127121/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
https://github.com/python/cpython/pull/127121/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
https://github.com/python/cpython/pull/127121/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
gpsheadhttps://github.com/gpshead
Nov 23, 2024https://github.com/python/cpython/pull/127121/files#r1855233681
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/127121/files
https://github.com/python/cpython/pull/127121/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
gpsheadhttps://github.com/gpshead
Nov 23, 2024https://github.com/python/cpython/pull/127121/files#r1855233539
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/127121/files
https://github.com/python/cpython/pull/127121/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L265
Python/import.chttps://github.com/python/cpython/pull/127121/files#diff-28cfc3e2868980a79d93d2ebdc8747dcb9231f3dd7f2caef96e74107d1ea3bf3
View file https://github.com/python/cpython/blob/2aad2d5db78d0e45574b3a571804b79b12154880/Python/import.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/127121/{{ revealButtonHref }}
https://github.com/python/cpython/pull/127121/files#diff-28cfc3e2868980a79d93d2ebdc8747dcb9231f3dd7f2caef96e74107d1ea3bf3
https://github.com/python/cpython/pull/127121/files#diff-28cfc3e2868980a79d93d2ebdc8747dcb9231f3dd7f2caef96e74107d1ea3bf3
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L321
Python/pystate.chttps://github.com/python/cpython/pull/127121/files#diff-7ac11e526f79b42d6ea9d3592cb99da46775640c69fa5510f4a6de87cced7141
View file https://github.com/python/cpython/blob/2aad2d5db78d0e45574b3a571804b79b12154880/Python/pystate.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/127121/{{ revealButtonHref }}
https://github.com/python/cpython/pull/127121/files#diff-7ac11e526f79b42d6ea9d3592cb99da46775640c69fa5510f4a6de87cced7141
https://github.com/python/cpython/pull/127121/files#diff-7ac11e526f79b42d6ea9d3592cb99da46775640c69fa5510f4a6de87cced7141
gpsheadhttps://github.com/gpshead
Nov 23, 2024https://github.com/python/cpython/pull/127121/files#r1855234017
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/127121/files
https://github.com/python/cpython/pull/127121/files#diff-7ac11e526f79b42d6ea9d3592cb99da46775640c69fa5510f4a6de87cced7141
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.