Skip to content

Conversation

@eddymul
Copy link
Contributor

@eddymul eddymul commented May 21, 2025

multiprocessing.freeze_support() now checks for work on any "spawn"
start method platform rather than only on Windows.


📚 Documentation preview 📚: https://cpython-previews--134462.org.readthedocs.build/en/134462/library/multiprocessing.html#multiprocessing.freeze_support

…ge to specify spawn method instead of platform
@eddymul eddymul requested a review from gpshead as a code owner May 21, 2025 19:09
@python-cla-bot
Copy link

python-cla-bot bot commented May 21, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@gpshead
Copy link
Member

gpshead commented May 24, 2025

reading things over, i'm convinced you are correct that this needs to not just use a win32 check. i moved my #134617 changes over into this PR.

@gpshead gpshead changed the title gh-80334: Doc/library/multiprocessing.rst: freeze_support: Change to … gh-80334: fix multiprocessing.freeze_support for other spawn platforms May 24, 2025
@gpshead gpshead self-assigned this May 24, 2025
@gpshead gpshead added type-bug An unexpected behavior, bug, or error and removed skip news labels May 24, 2025
@gpshead gpshead enabled auto-merge (squash) May 24, 2025 03:31
@gpshead gpshead merged commit 80284b5 into python:main May 24, 2025
43 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs May 24, 2025
@miss-islington-app
Copy link

Thanks @eddymul for the PR, and @gpshead for merging it 🌮🎉.. 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 May 24, 2025
…atforms (pythonGH-134462)

Doc/library/multiprocessing.rst: freeze_support: Change to specify spawn method instead of platform
Have multiprocessing.freeze_support() enable on spawn, not just win32.

---------
(cherry picked from commit 80284b5)

Co-authored-by: Eddy Mulyono <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 24, 2025
…atforms (pythonGH-134462)

Doc/library/multiprocessing.rst: freeze_support: Change to specify spawn method instead of platform
Have multiprocessing.freeze_support() enable on spawn, not just win32.

---------
(cherry picked from commit 80284b5)

Co-authored-by: Eddy Mulyono <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented May 24, 2025

GH-134619 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 May 24, 2025
@bedevere-app
Copy link

bedevere-app bot commented May 24, 2025

GH-134620 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 May 24, 2025
gpshead added a commit that referenced this pull request May 24, 2025
…latforms (GH-134462) (#134620)

gh-80334: fix multiprocessing.freeze_support for other spawn platforms (GH-134462)

Doc/library/multiprocessing.rst: freeze_support: Change to specify spawn method instead of platform
Have multiprocessing.freeze_support() enable on spawn, not just win32.

---------
(cherry picked from commit 80284b5)

Co-authored-by: Eddy Mulyono <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
gpshead added a commit that referenced this pull request May 24, 2025
…latforms (GH-134462) (#134619)

gh-80334: fix multiprocessing.freeze_support for other spawn platforms (GH-134462)

Doc/library/multiprocessing.rst: freeze_support: Change to specify spawn method instead of platform
Have multiprocessing.freeze_support() enable on spawn, not just win32.

---------
(cherry picked from commit 80284b5)

Co-authored-by: Eddy Mulyono <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Windows Server 2022 NoGIL 3.13 (tier-1) has failed when building commit 44d1849.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1488/builds/1340) and take a look at the build logs.
  4. Check if the failure is related to this commit (44d1849) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1488/builds/1340

Failed tests:

  • test_launcher

Failed subtests:

  • test_search_major_3 - test.test_launcher.TestLauncher.test_search_major_3
  • test_search_major_2 - test.test_launcher.TestLauncher.test_search_major_2

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "C:\Users\Administrator\buildarea\3.13.itamaro-win64-srv-22-aws.x64.nogil\build\Lib\test\test_launcher.py", line 445, in test_search_major_3
    self.assertEqual("PythonCore", data["env.company"])
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'PythonCore' != 'PythonTestSuite'
- PythonCore
+ PythonTestSuite


Traceback (most recent call last):
  File "C:\Users\Administrator\buildarea\3.13.itamaro-win64-srv-22-aws.x64.nogil\build\Lib\test\test_launcher.py", line 465, in test_search_major_2
    self.assertEqual("PythonCore", data["env.company"])
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'PythonCore' != 'PythonTestSuite'
- PythonCore
+ PythonTestSuite

@marcelotduarte
Copy link

This patch breaks set_start_method for use in Python (not frozen) and also breaks it for cx_Freeze.
A simple sample using 'spaw', but also breaks with 'fork' or 'forkserver':

import multiprocessing

def foo(q):
    q.put("Hello from cx_Freeze")

if __name__ == "__main__":
    multiprocessing.freeze_support()
    multiprocessing.set_start_method('spawn')
    q = multiprocessing.SimpleQueue()
    p = multiprocessing.Process(target=foo, args=(q,))
    p.start()
    print(q.get())
    p.join()

This sample worked before in windows and linux for python 3.9 until python 3.13.3.
For cx_Freeze I made a temporary fix.

I suspect that a correct fix is change the line 148 from:
if self.get_start_method() == 'spawn' and getattr(sys, 'frozen', False):
to a simple:
if getattr(sys, 'frozen', False):

@ZeroIntensity
Copy link
Member

@marcelotduarte Please make a new issue so we can track this.

@marcelotduarte
Copy link

Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
…atforms (pythonGH-134462)

Doc/library/multiprocessing.rst: freeze_support: Change to specify spawn method instead of platform
Have multiprocessing.freeze_support() enable on spawn, not just win32.

---------

Co-authored-by: Gregory P. Smith <[email protected]>
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
…atforms (pythonGH-134462)

Doc/library/multiprocessing.rst: freeze_support: Change to specify spawn method instead of platform
Have multiprocessing.freeze_support() enable on spawn, not just win32.

---------

Co-authored-by: Gregory P. Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir topic-multiprocessing type-bug An unexpected behavior, bug, or error

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants