From 7dcf6e1eec3ef8c895bb4cdae34b8e561968d351 Mon Sep 17 00:00:00 2001 From: Maksim Ivanov Date: Fri, 22 Aug 2025 11:44:10 +0200 Subject: [PATCH 1/3] gh-137996: Fix path to __main__ in forkserver preload logic Let the __main__ module be preloaded by extracting the necessary path from the spawn.get_preparation_data() result. --- Lib/multiprocessing/forkserver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/multiprocessing/forkserver.py b/Lib/multiprocessing/forkserver.py index c91891ff162c2d..14b465c3a08bf8 100644 --- a/Lib/multiprocessing/forkserver.py +++ b/Lib/multiprocessing/forkserver.py @@ -146,9 +146,9 @@ def ensure_running(self): 'main(%d, %d, %r, **%r)') if self._preload_modules: - desired_keys = {'main_path', 'sys_path'} + desired_keys = {'main_path': 'init_main_from_path', 'sys_path': 'sys_path'} data = spawn.get_preparation_data('ignore') - main_kws = {x: y for x, y in data.items() if x in desired_keys} + main_kws = {x: data[y] for x, y in desired_keys.items() if y in data} else: main_kws = {} From 8882e4ba485502e453291a8e8ec16bfd5fdcc5a6 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 23 Aug 2025 01:00:00 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2025-08-23-00-59-59.gh-issue-137996.6pkMXl.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-08-23-00-59-59.gh-issue-137996.6pkMXl.rst diff --git a/Misc/NEWS.d/next/Library/2025-08-23-00-59-59.gh-issue-137996.6pkMXl.rst b/Misc/NEWS.d/next/Library/2025-08-23-00-59-59.gh-issue-137996.6pkMXl.rst new file mode 100644 index 00000000000000..f83a2b731b6df5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-08-23-00-59-59.gh-issue-137996.6pkMXl.rst @@ -0,0 +1 @@ +Fix preloading of __main__ for forkserver multiprocessing. From 9305b2a3c6ce6abb5102cc345d9f04691a1811aa Mon Sep 17 00:00:00 2001 From: Maksim Ivanov Date: Sat, 23 Aug 2025 23:17:05 +0200 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Library/2025-08-23-00-59-59.gh-issue-137996.6pkMXl.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- .../Library/2025-08-23-00-59-59.gh-issue-137996.6pkMXl.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-08-23-00-59-59.gh-issue-137996.6pkMXl.rst b/Misc/NEWS.d/next/Library/2025-08-23-00-59-59.gh-issue-137996.6pkMXl.rst index f83a2b731b6df5..e70a5b1135bcae 100644 --- a/Misc/NEWS.d/next/Library/2025-08-23-00-59-59.gh-issue-137996.6pkMXl.rst +++ b/Misc/NEWS.d/next/Library/2025-08-23-00-59-59.gh-issue-137996.6pkMXl.rst @@ -1 +1,3 @@ -Fix preloading of __main__ for forkserver multiprocessing. +:mod:`multiprocessing`: Fix preloading of ``__main__`` for +:ref:`forkserver ` +start method.