Skip to content

gh-140814: Fix freeze_support() setting start method as side effect#144608

Merged
gpshead merged 4 commits intopython:mainfrom
gpshead:gh-140814-freeze-support-side-effect
Mar 16, 2026
Merged

gh-140814: Fix freeze_support() setting start method as side effect#144608
gpshead merged 4 commits intopython:mainfrom
gpshead:gh-140814-freeze-support-side-effect

Conversation

@gpshead
Copy link
Member

@gpshead gpshead commented Feb 8, 2026

Summary

  • freeze_support() called get_start_method() without allow_none=True, which locked in the default start method context as a side effect. This caused a subsequent set_start_method() call to raise RuntimeError: context has already been set.
  • Use allow_none=True and accept None as a matching value, since spawn.freeze_support() independently detects spawned child processes.
  • Check sys.frozen first as the more likely short-circuit (almost always False).

…fect

freeze_support() called get_start_method() without allow_none=True,
which locked in the default start method context. This caused a
subsequent set_start_method() call to raise "context has already been
set". Use allow_none=True and accept None as a matching value, since
spawn.freeze_support() independently detects spawned child processes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Test that freeze_support() does not lock in the default start method,
which would prevent a subsequent set_start_method() call.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gpshead gpshead added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 8, 2026
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @gpshead for commit 31d115f 🤖

Results will be shown at:

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

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 8, 2026
@gpshead gpshead requested a review from picnixz February 8, 2026 23:25
@gpshead gpshead marked this pull request as ready for review February 8, 2026 23:26
@gpshead gpshead added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Feb 8, 2026
@picnixz
Copy link
Member

picnixz commented Mar 15, 2026

@gpshead Ok for merging this? (I've updated the branch with my suggestion).

@gpshead gpshead merged commit ee53180 into python:main Mar 16, 2026
47 checks passed
@miss-islington-app
Copy link

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 16, 2026
…fect (pythonGH-144608)

freeze_support() called get_start_method() without allow_none=True,
which locked in the default start method context. This caused a
subsequent set_start_method() call to raise "context has already been
set". Use allow_none=True and accept None as a matching value, since
spawn.freeze_support() independently detects spawned child processes.

Test that freeze_support() does not lock in the default start method,
which would prevent a subsequent set_start_method() call.
(cherry picked from commit ee53180)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 16, 2026
…fect (pythonGH-144608)

freeze_support() called get_start_method() without allow_none=True,
which locked in the default start method context. This caused a
subsequent set_start_method() call to raise "context has already been
set". Use allow_none=True and accept None as a matching value, since
spawn.freeze_support() independently detects spawned child processes.

Test that freeze_support() does not lock in the default start method,
which would prevent a subsequent set_start_method() call.
(cherry picked from commit ee53180)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 16, 2026

GH-146008 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Mar 16, 2026
@bedevere-app
Copy link

bedevere-app bot commented Mar 16, 2026

GH-146009 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Mar 16, 2026
gpshead added a commit that referenced this pull request Mar 16, 2026
…ffect (GH-144608) (#146009)

gh-140814: Fix freeze_support() setting start method as side effect (GH-144608)

freeze_support() called get_start_method() without allow_none=True,
which locked in the default start method context. This caused a
subsequent set_start_method() call to raise "context has already been
set". Use allow_none=True and accept None as a matching value, since
spawn.freeze_support() independently detects spawned child processes.

Test that freeze_support() does not lock in the default start method,
which would prevent a subsequent set_start_method() call.
(cherry picked from commit ee53180)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
gpshead added a commit that referenced this pull request Mar 16, 2026
…ffect (GH-144608) (#146008)

gh-140814: Fix freeze_support() setting start method as side effect (GH-144608)

freeze_support() called get_start_method() without allow_none=True,
which locked in the default start method context. This caused a
subsequent set_start_method() call to raise "context has already been
set". Use allow_none=True and accept None as a matching value, since
spawn.freeze_support() independently detects spawned child processes.

Test that freeze_support() does not lock in the default start method,
which would prevent a subsequent set_start_method() call.
(cherry picked from commit ee53180)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
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.

3 participants