René's URL Explorer Experiment


Title: gh-155717: Determine multiprocessing's default start method lazily by gpshead · Pull Request #159254 · python/cpython · GitHub

Open Graph Title: gh-155717: Determine multiprocessing's default start method lazily by gpshead · Pull Request #159254 · python/cpython

X Title: gh-155717: Determine multiprocessing's default start method lazily by gpshead · Pull Request #159254 · python/cpython

Description: gh-155827 made import multiprocessing check whether the temporary directory is writeable, to choose between forkserver and spawn as the default start method. Doing that at import time is a startup regression, reported by Leandro Damascena in #155717 (comment): the import now also loads multiprocessing.util, subprocess, tempfile, shutil and random, even in programs that never start a process. Spawned children, the fork server and the resource tracker pay it too, as each imports multiprocessing. This keeps the behaviour of gh-155827 but determines the default start method the first time it is needed, as that comment suggested. Changes DefaultContext resolves the platform default on first use (get_context(), get_start_method(), get_all_start_methods(), or starting a default Process) and caches it. get_start_method(allow_none=True) still returns None without resolving anything. multiprocessing.context no longer imports multiprocessing.util at the top level, and multiprocessing.util imports tempfile only where it is used, as before gh-155827. Includes the fix from gh-158410 by Vyron Vasileiadis, with a test adapted from that PR: _has_writeable_tempdir() returns false instead of raising FileNotFoundError when tempfile finds no usable temporary directory at all. With the lazy change alone that error would only move from import to first use, so both are needed. This PR supersedes gh-158410. Documents the fallback in the forkserver start method description, with a versionchanged. flowchart TB subgraph before["Before (gh-155827)"] direction TB b1["import multiprocessing"] --> b2["import multiprocessing.util,
subprocess, tempfile, shutil, random"] b2 --> b3{"can a temporary file
be created?"} b3 -- "yes" --> b4["default = forkserver"] b3 -- "no" --> b5["default = spawn"] b3 -- "no usable temp
directory at all" --> b6["import fails with
FileNotFoundError"] b4 --> b7["first get_context() /
Process.start()"] b5 --> b7 b7 --> b8["use the default
chosen at import"] end subgraph after["After (this PR)"] direction TB a1["import multiprocessing"] --> a2["no extra imports,
no default chosen yet"] a2 --> a3["first get_context() /
Process.start()"] a3 --> a4["import multiprocessing.util
and tempfile"] a4 --> a5{"can a temporary file
be created?"} a5 -- "yes" --> a6["default = forkserver"] a5 -- "no, or no usable
temp directory at all" --> a7["default = spawn"] a6 --> a8["cache and use
the default"] a7 --> a8 end Loading The diagram shows POSIX platforms that support forkserver, other than macOS. Windows and macOS always default to spawn and never run the check; that is unchanged. Measurements Linux x86_64, -O3 non-PGO build, whole-process wall time, median of 140 interleaved runs. "Before gh-155827" uses the Lib/multiprocessing package from the parent of that commit. Before gh-155827 main This PR import multiprocessing 24.3 ms 35.9 ms 23.8 ms from multiprocessing import cpu_count; cpu_count() 24.1 ms 36.0 ms 23.9 ms modules in sys.modules after the import 67 101 67 Behaviour notes The check now reflects the temporary directory configuration at first use instead of at import. A process whose start method is set explicitly, which includes spawn and forkserver children of a parent using the default, does not run the check unless it asks for the default: get_all_start_methods(), or get_context() while no start method is set. DefaultContext._default_context is now a functools.cached_property. It can still be read, assigned, deleted and patched like the plain attribute it was, and DefaultContext(context) still accepts an explicit default. Backports This needs backporting to 3.15: the 3.15 backport of gh-155827 (gh-155887) was merged on 2026-10-10, so the 3.15 branch currently has the import-time check, including the FileNotFoundError on import when there is no usable temporary directory. The 3.14 backport (gh-155886) is still open and should pick this up before it is merged. There is no new NEWS entry: the entry from gh-155827 is still in Misc/NEWS.d/next/ on both main and 3.15 and still describes the user-visible change. If a release containing gh-155827 goes out before this lands on that branch, this needs its own NEWS entry there. Authored using Claude, reviewed by me. Issue: gh-155717

Open Graph Description: gh-155827 made import multiprocessing check whether the temporary directory is writeable, to choose between forkserver and spawn as the default start method. Doing that at import time is a startup ...

X Description: gh-155827 made import multiprocessing check whether the temporary directory is writeable, to choose between forkserver and spawn as the default start method. Doing that at import time is a startup ...

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

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:fcd937ca-d311-69e2-67bf-ff264eb0bc4b
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idBCE8:E0ADF:1B730CB:2291929:6B0233AD
html-safe-noncea11d6b12c2b109cafd224a59e14de7b98c5e667ccc8bab387b3f8d627a002bc2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0U4OkUwQURGOjFCNzMwQ0I6MjI5MTkyOTo2QjAyMzNBRCIsInZpc2l0b3JfaWQiOiI4NTk1NjE2MTQ0MDM4MTc5NzU3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacc0b0dd57f3573ffce6ee3f3ffe90f5a43eaa0a4e64e0b75db985bafb2860698c
hovercard-subject-tagpull_request:4834268218
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/159254/files
twitter:imagehttps://avatars.githubusercontent.com/u/68491?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/68491?s=400&v=4
og:image:altgh-155827 made import multiprocessing check whether the temporary directory is writeable, to choose between forkserver and spawn as the default start method. Doing that at import time is a startup ...
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/159254/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F159254%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%2F159254%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/159254/files
Reloadhttps://github.com/python/cpython/pull/159254/files
Reloadhttps://github.com/python/cpython/pull/159254/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
gpsheadhttps://github.com/gpshead
python:mainhttps://github.com/python/cpython/tree/main
gpshead:gh-155717-lazy-default-contexthttps://github.com/gpshead/cpython/tree/gh-155717-lazy-default-context
Conversation 14 https://github.com/python/cpython/pull/159254
Commits 1 https://github.com/python/cpython/pull/159254/commits
Checks 62 https://github.com/python/cpython/pull/159254/checks
Files changed https://github.com/python/cpython/pull/159254/files
Please reload this pagehttps://github.com/python/cpython/pull/159254/files
gh-155717: Determine multiprocessing's default start method lazily https://github.com/python/cpython/pull/159254/files#top
Show all changes 1 commit https://github.com/python/cpython/pull/159254/files
2737e92 gh-155717: Determine multiprocessing's default start method lazily gpshead Oct 12, 2026 https://github.com/python/cpython/pull/159254/commits/2737e92413f8b4c76f3b1ecc7e921f977fba181c
Clear filters https://github.com/python/cpython/pull/159254/files
Please reload this pagehttps://github.com/python/cpython/pull/159254/files
Please reload this pagehttps://github.com/python/cpython/pull/159254/files
multiprocessing.rst https://github.com/python/cpython/pull/159254/files#diff-2cf07acf4f2d547e93e35c6a4ba2ee818e991b54e88da4a904ee0a49acb99eb3
context.py https://github.com/python/cpython/pull/159254/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
util.py https://github.com/python/cpython/pull/159254/files#diff-42fd0a5b0b915b3c07ea405771fcf122210ff0ce5be1ad4b086d6016eec0330f
_test_multiprocessing.py https://github.com/python/cpython/pull/159254/files#diff-c3db62f7c1928499afd71830c22c8bb8f56843a4533cecf69137973d73c489fc
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L540
Doc/library/multiprocessing.rsthttps://github.com/python/cpython/pull/159254/files#diff-2cf07acf4f2d547e93e35c6a4ba2ee818e991b54e88da4a904ee0a49acb99eb3
View file https://github.com/gpshead/cpython/blob/2737e92413f8b4c76f3b1ecc7e921f977fba181c/Doc/library/multiprocessing.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/159254/{{ revealButtonHref }}
https://github.com/python/cpython/pull/159254/files#diff-2cf07acf4f2d547e93e35c6a4ba2ee818e991b54e88da4a904ee0a49acb99eb3
Please reload this pagehttps://github.com/python/cpython/pull/159254/files
https://github.com/python/cpython/pull/159254/files#diff-2cf07acf4f2d547e93e35c6a4ba2ee818e991b54e88da4a904ee0a49acb99eb3
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L541
Lib/multiprocessing/context.pyhttps://github.com/python/cpython/pull/159254/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
View file https://github.com/gpshead/cpython/blob/2737e92413f8b4c76f3b1ecc7e921f977fba181c/Lib/multiprocessing/context.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/159254/{{ revealButtonHref }}
https://github.com/python/cpython/pull/159254/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
https://github.com/python/cpython/pull/159254/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
https://github.com/python/cpython/pull/159254/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
https://github.com/python/cpython/pull/159254/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
https://github.com/python/cpython/pull/159254/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
https://github.com/python/cpython/pull/159254/files#diff-68368c7bc63449f34e9b6e6f13715852f23061c0bf6497b1a9691c0860943f49
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L541
Lib/multiprocessing/util.pyhttps://github.com/python/cpython/pull/159254/files#diff-42fd0a5b0b915b3c07ea405771fcf122210ff0ce5be1ad4b086d6016eec0330f
View file https://github.com/gpshead/cpython/blob/2737e92413f8b4c76f3b1ecc7e921f977fba181c/Lib/multiprocessing/util.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/159254/{{ revealButtonHref }}
https://github.com/python/cpython/pull/159254/files#diff-42fd0a5b0b915b3c07ea405771fcf122210ff0ce5be1ad4b086d6016eec0330f
https://github.com/python/cpython/pull/159254/files#diff-42fd0a5b0b915b3c07ea405771fcf122210ff0ce5be1ad4b086d6016eec0330f
https://github.com/python/cpython/pull/159254/files#diff-42fd0a5b0b915b3c07ea405771fcf122210ff0ce5be1ad4b086d6016eec0330f
Please reload this pagehttps://github.com/python/cpython/pull/159254/files
https://github.com/python/cpython/pull/159254/files#diff-42fd0a5b0b915b3c07ea405771fcf122210ff0ce5be1ad4b086d6016eec0330f
https://github.com/python/cpython/pull/159254/files#diff-42fd0a5b0b915b3c07ea405771fcf122210ff0ce5be1ad4b086d6016eec0330f
Please reload this pagehttps://github.com/python/cpython/pull/159254/files
https://github.com/python/cpython/pull/159254/files#diff-42fd0a5b0b915b3c07ea405771fcf122210ff0ce5be1ad4b086d6016eec0330f
https://github.com/python/cpython/pull/159254/files#diff-42fd0a5b0b915b3c07ea405771fcf122210ff0ce5be1ad4b086d6016eec0330f
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L542
Lib/test/_test_multiprocessing.pyhttps://github.com/python/cpython/pull/159254/files#diff-c3db62f7c1928499afd71830c22c8bb8f56843a4533cecf69137973d73c489fc
View file https://github.com/gpshead/cpython/blob/2737e92413f8b4c76f3b1ecc7e921f977fba181c/Lib/test/_test_multiprocessing.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/159254/{{ revealButtonHref }}
https://github.com/python/cpython/pull/159254/files#diff-c3db62f7c1928499afd71830c22c8bb8f56843a4533cecf69137973d73c489fc
https://github.com/python/cpython/pull/159254/files#diff-c3db62f7c1928499afd71830c22c8bb8f56843a4533cecf69137973d73c489fc
Please reload this pagehttps://github.com/python/cpython/pull/159254/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.