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.

---------

Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
Eddy Mulyono 2025-05-23 23:50:19 -04:00 committed by GitHub
parent 74a9c60f3e
commit 80284b5c5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 6 deletions

View file

@ -1081,7 +1081,7 @@ Miscellaneous
.. function:: freeze_support() .. function:: freeze_support()
Add support for when a program which uses :mod:`multiprocessing` has been Add support for when a program which uses :mod:`multiprocessing` has been
frozen to produce a Windows executable. (Has been tested with **py2exe**, frozen to produce an executable. (Has been tested with **py2exe**,
**PyInstaller** and **cx_Freeze**.) **PyInstaller** and **cx_Freeze**.)
One needs to call this function straight after the ``if __name__ == One needs to call this function straight after the ``if __name__ ==
@ -1099,10 +1099,10 @@ Miscellaneous
If the ``freeze_support()`` line is omitted then trying to run the frozen If the ``freeze_support()`` line is omitted then trying to run the frozen
executable will raise :exc:`RuntimeError`. executable will raise :exc:`RuntimeError`.
Calling ``freeze_support()`` has no effect when invoked on any operating Calling ``freeze_support()`` has no effect when the start method is not
system other than Windows. In addition, if the module is being run *spawn*. In addition, if the module is being run normally by the Python
normally by the Python interpreter on Windows (the program has not been interpreter (the program has not been frozen), then ``freeze_support()``
frozen), then ``freeze_support()`` has no effect. has no effect.
.. function:: get_all_start_methods() .. function:: get_all_start_methods()

View file

@ -145,7 +145,7 @@ class BaseContext(object):
'''Check whether this is a fake forked process in a frozen executable. '''Check whether this is a fake forked process in a frozen executable.
If so then run code specified by commandline and exit. If so then run code specified by commandline and exit.
''' '''
if sys.platform == 'win32' and getattr(sys, 'frozen', False): if self.get_start_method() == 'spawn' and getattr(sys, 'frozen', False):
from .spawn import freeze_support from .spawn import freeze_support
freeze_support() freeze_support()

View file

@ -0,0 +1,2 @@
:func:`multiprocessing.freeze_support` now checks for work on any "spawn"
start method platform rather than only on Windows.