Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.14] gh-143706: Fix sys.argv not set during multiprocessing forkserver__main__ preload (GH-143717)#143763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gpshead merged 1 commit intopython:3.14frommiss-islington:backport-298d544-3.14
Jan 13, 2026
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletionLib/multiprocessing/forkserver.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -152,6 +152,8 @@ def ensure_running(self):
main_kws['sys_path'] = data['sys_path']
if 'init_main_from_path' in data:
main_kws['main_path'] = data['init_main_from_path']
if 'sys_argv' in data:
main_kws['sys_argv'] = data['sys_argv']

with socket.socket(socket.AF_UNIX) as listener:
address = connection.arbitrary_address('AF_UNIX')
Expand DownExpand Up@@ -197,7 +199,7 @@ def ensure_running(self):
#

def main(listener_fd, alive_r, preload, main_path=None, sys_path=None,
*, authkey_r=None):
*,sys_argv=None,authkey_r=None):
"""Run forkserver."""
if authkey_r is not None:
try:
Expand All@@ -209,6 +211,8 @@ def main(listener_fd, alive_r, preload, main_path=None, sys_path=None,
authkey = b''

if preload:
if sys_argv is not None:
sys.argv[:] = sys_argv
if sys_path is not None:
sys.path[:] = sys_path
if '__main__' in preload and main_path is not None:
Expand Down
20 changes: 20 additions & 0 deletionsLib/test/_test_multiprocessing.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6939,6 +6939,26 @@ def test_preload_main(self):
out = out.decode().split("\n")
self.assertEqual(out, ['__main__', '__mp_main__', 'f', 'f', ''])

def test_preload_main_sys_argv(self):
# gh-143706: Check that sys.argv is set before __main__ is pre-loaded
if multiprocessing.get_start_method() != "forkserver":
self.skipTest("forkserver specific test")

name = os.path.join(os.path.dirname(__file__), 'mp_preload_sysargv.py')
_, out, err = test.support.script_helper.assert_python_ok(
name, 'foo', 'bar')
self.assertEqual(err, b'')

out = out.decode().split("\n")
expected_argv = "['foo', 'bar']"
self.assertEqual(out, [
f"module:{expected_argv}",
f"fun:{expected_argv}",
f"module:{expected_argv}",
f"fun:{expected_argv}",
'',
])

#
# Mixins
#
Expand Down
22 changes: 22 additions & 0 deletionsLib/test/mp_preload_sysargv.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
# gh-143706: Test that sys.argv is correctly set during main module import
# when using forkserver with __main__ preloading.

import multiprocessing
import sys

# This will be printed during module import - sys.argv should be correct here
print(f"module:{sys.argv[1:]}")

def fun():
# This will be printed when the function is called
print(f"fun:{sys.argv[1:]}")

if __name__ == "__main__":
ctx = multiprocessing.get_context("forkserver")
ctx.set_forkserver_preload(['__main__'])

fun()

p = ctx.Process(target=fun)
p.start()
p.join()
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
Fix :mod:`multiprocessing` forkserver so that :data:`sys.argv` is correctly
set before ``__main__`` is preloaded. Previously, :data:`sys.argv` was empty
during main module import in forkserver child processes. This fixes a
regression introduced in 3.13.8 and 3.14.1. Root caused by Aaron Wieczorek,
test provided by Thomas Watson, thanks!
Loading

[8]ページ先頭

©2009-2026 Movatter.jp