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

sys.argv no longer correct during main module execution usingforkserver #143706

Closed
Assignees
gpshead
Labels
3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-multiprocessingtype-bugAn unexpected behavior, bug, or error
@tpwrules

Description

@tpwrules

Bug report

Bug description:

The following code, invoked withpython3 ~/test.py foo:

importmultiprocessingimportsysprint("args in module",sys.argv[1:])deffun():print("args in fun",sys.argv[1:])if__name__=="__main__":multiprocessing.set_start_method("forkserver")fun()p=multiprocessing.Process(target=fun)p.start()p.join()

prints the following results on Python 3.12, 3.13.4, and 3.14.0b3:

args in module ['foo']args in fun ['foo']args in module ['foo']args in fun ['foo']

but on Python 3.13.11 and 3.14.2 prints the following results:

args in module ['foo']args in fun ['foo']args in module []args in fun ['foo']

For whatever reason, these latter versions changeforkserver to set upsys.argv after the main module is imported, instead of before. As far as I can tell, the former results are always printed usingspawn; that always sets upsys.argv before the main module is imported.

If the code depends onsys.argv in the main module, then the subprocess does not do the same thing as the main process and bad things can happen.

This change tripped me up when fixing a program for the newforkserver default. It's unclear if it's a bug, because I admit our program is naughty about running code in a module like this, but this may be something to fix and at least may serve as documentation of a pitfall for others even if there is nothing to change.

CPython versions tested on:

3.12, 3.13, 3.14

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

Labels

3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-multiprocessingtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2026 Movatter.jp