HEX
Server: LiteSpeed
System: Linux s1296.sgp1.mysecurecloudhost.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: bishwesh (1878)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //opt/alt/python313/lib64/python3.13/test/mp_preload_large_sysargv.py
# gh-144503: Test that the forkserver can start when the parent process has
# a very large sys.argv.  Prior to the fix, sys.argv was repr'd into the
# forkserver ``-c`` command string which could exceed the OS limit on the
# length of a single argv element (MAX_ARG_STRLEN on Linux, ~128 KiB),
# causing posix_spawn to fail and the parent to see a BrokenPipeError.

import multiprocessing
import sys

EXPECTED_LEN = 5002  # argv[0] + 5000 padding entries + sentinel


def fun():
    print(f"worker:{len(sys.argv)}:{sys.argv[-1]}")


if __name__ == "__main__":
    # Inflate sys.argv well past 128 KiB before the forkserver is started.
    sys.argv[1:] = ["x" * 50] * 5000 + ["sentinel"]
    assert len(sys.argv) == EXPECTED_LEN

    ctx = multiprocessing.get_context("forkserver")
    p = ctx.Process(target=fun)
    p.start()
    p.join()
    sys.exit(p.exitcode)
else:
    # This branch runs when the forkserver preloads this module as
    # __mp_main__; confirm the large argv was propagated intact.
    print(f"preload:{len(sys.argv)}:{sys.argv[-1]}")