]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-80334: fix multiprocessing.freeze_support for other spawn platforms (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 24 May 2025 04:13:37 +0000 (06:13 +0200)
committerGitHub <noreply@github.com>
Sat, 24 May 2025 04:13:37 +0000 (04:13 +0000)
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 80284b5c5eebd0e603c38322f94a97a2853ceeba)

Co-authored-by: Eddy Mulyono <eddymul@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Doc/library/multiprocessing.rst
Lib/multiprocessing/context.py
Misc/NEWS.d/next/Library/2025-05-24-03-10-36.gh-issue-80334.z21cMa.rst [new file with mode: 0644]

index 38104bb7c5f4d47d9184b23b5bc40b871a06217c..f5591a32f59dc70107d3cc95736c3ff9bc4151ee 100644 (file)
@@ -1042,7 +1042,7 @@ Miscellaneous
 .. function:: freeze_support()
 
    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**.)
 
    One needs to call this function straight after the ``if __name__ ==
@@ -1060,10 +1060,10 @@ Miscellaneous
    If the ``freeze_support()`` line is omitted then trying to run the frozen
    executable will raise :exc:`RuntimeError`.
 
-   Calling ``freeze_support()`` has no effect when invoked on any operating
-   system other than Windows.  In addition, if the module is being run
-   normally by the Python interpreter on Windows (the program has not been
-   frozen), then ``freeze_support()`` has no effect.
+   Calling ``freeze_support()`` has no effect when the start method is not
+   *spawn*. In addition, if the module is being run normally by the Python
+   interpreter (the program has not been frozen), then ``freeze_support()``
+   has no effect.
 
 .. function:: get_all_start_methods()
 
index de8a264829dff3b5598501a3fa950918a2158fda..f395e8b04d0cc1760e6462640ada7d0957df36bc 100644 (file)
@@ -145,7 +145,7 @@ class BaseContext(object):
         '''Check whether this is a fake forked process in a frozen executable.
         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
             freeze_support()
 
diff --git a/Misc/NEWS.d/next/Library/2025-05-24-03-10-36.gh-issue-80334.z21cMa.rst b/Misc/NEWS.d/next/Library/2025-05-24-03-10-36.gh-issue-80334.z21cMa.rst
new file mode 100644 (file)
index 0000000..2284295
--- /dev/null
@@ -0,0 +1,2 @@
+:func:`multiprocessing.freeze_support` now checks for work on any "spawn"
+start method platform rather than only on Windows.