Skip to content

[3.14] gh-155717: use spawn as the default start method for read-only filesystems (GH-155827) - #155886

Merged
gpshead merged 4 commits into
python:3.14from
miss-islington:backport-c144799-3.14
Oct 13, 2026
Merged

gpshead merged 4 commits into
python:3.14from
miss-islington:backport-c144799-3.14

Conversation

@miss-islington

@miss-islington miss-islington commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

The "forkserver" start method (the default start method on non-Windows systems)
requires the ability to write temporary files, which is not possible if TMPDIR
is read-only (e.g., k8s containers mounted with readOnlyRootFilesystem=True).

On such filesystems, the default start method changes from "forkserver" to "spawn".
(cherry picked from commit c144799)

Co-authored-by: Bénédikt Tran 10796600+picnixz@users.noreply.github.com


I rebased this backport on current 3.14 and updated it to also include the changes to avoid the performance regression from #159271 via #159254. --@gpshead

@picnixz

picnixz commented Aug 16, 2026

Copy link
Copy Markdown
Member

Waiting until #155891 is merged.

Comment thread Lib/test/_test_multiprocessing.py
@picnixz
picnixz marked this pull request as ready for review August 16, 2026 09:45
@picnixz

picnixz commented Aug 16, 2026

Copy link
Copy Markdown
Member

!buildbot root

@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @picnixz for commit 0e1100c 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F155886%2Fmerge

The command will test the builders whose names match following regular expression: root

The builders matched are:

  • AMD64 Debian root PR

@picnixz
picnixz marked this pull request as draft August 16, 2026 10:32
@picnixz

picnixz commented Aug 16, 2026

Copy link
Copy Markdown
Member

I have other matters to attend so this will need to wait.

@gpshead gpshead self-assigned this Oct 12, 2026
@gpshead

gpshead commented Oct 12, 2026

Copy link
Copy Markdown
Member

see the issue, this causes a startup time performance regression. holding off is good for now.

picnixz and others added 4 commits October 12, 2026 22:36
…y filesystems (pythonGH-155827)

The "forkserver" start method (the default start method on non-Windows systems)
requires the ability to write temporary files, which is not possible if TMPDIR
is read-only (e.g., k8s containers mounted with `readOnlyRootFilesystem=True`).

On such filesystems, the default start method changes from "forkserver" to "spawn".
(cherry picked from commit c144799)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…hod lazily (pythonGH-159254)

pythongh-155827 made `import multiprocessing` check whether the temporary
directory is writeable in order to choose between "forkserver" and
"spawn" as the default start method. That check ran at import time and
pulled in `multiprocessing.util`, `subprocess`, `tempfile`, `shutil`
and `random`, noticeably slowing down the import for every program,
including ones that never start a process and every spawned child,
the fork server and the resource tracker.

The default start method is now determined the first time it is needed
instead: on the first `get_context()`, `get_start_method()`,
`get_all_start_methods()` or default `Process` start.
`multiprocessing.util` goes back to importing `tempfile` only where it
is used.

Also include the fix from pythongh-158410 by Vyron Vasileiadis, along with a
test adapted from that PR: when `tempfile` finds no usable temporary
directory at all, the check now reports that instead of raising
`FileNotFoundError`, so that "spawn" is chosen.

The regression was reported, and the lazy approach suggested, by
Leandro Damascena in
python#155717 (comment)

(cherry picked from commit 48ddda1)

Co-authored-by: Vyron Vasileiadis <hi@fedonman.com>
…hange

Say that the change applies when there is no writable temporary
directory and that starting a process previously failed there.
@gpshead
gpshead force-pushed the backport-c144799-3.14 branch from 0e1100c to f65fc7b Compare October 12, 2026 22:36
@gpshead
gpshead marked this pull request as ready for review October 12, 2026 22:41
@gpshead

gpshead commented Oct 12, 2026

Copy link
Copy Markdown
Member

I rebased this backport on current 3.14 and updated it to also include the changes to avoid the performance regression from #159271 via #159254.

@gpshead
gpshead merged commit 6719378 into python:3.14 Oct 13, 2026
50 of 51 checks passed
@miss-islington
miss-islington deleted the backport-c144799-3.14 branch October 13, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants