-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
multiprocessing forkserver main contains dead main_path= handling code #126631
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It did silently break something: import multiprocessing
import os
print(f"importing {__name__} ({__file__}) pid={os.getpid()}")
def runner():
print(f"running in {os.getpid()}")
if __name__ == '__main__':
multiprocessing.set_start_method('forkserver')
multiprocessing.set_forkserver_preload(['__main__'])
N=4
procs = [multiprocessing.Process(target=runner) for _ in range(N)]
for p in procs:
p.start()
for p in procs:
p.join() Currently:
If we fix it (and presumably before 3.4, although I haven't tested):
Having said that, no-one noticing for eleven years suggests it isn't actually required. Perhaps it would be better to simplify things and remove the code? I'll post a quick and dirty fix, for reference. |
The `main_path` parameter was renamed `init_main_from_name`, update the forkserver code accordingly.
FWIW one place where In fact, the fork server's default preload list is In trying to reshape the repro script into a regression test, I ran into some truly bizarre behaviour: it was working when run directly but produced spurious output when run as a unit test, even with the exact same command line and environment! It turns out the fork server is not flushing |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
The
multiprocessing
module's forkserver start methodmultiprocessing.forkserver.main
has two arguments that are values passed from the parent process to the forkserver when first launching it.main_path=
andsys_path=
. Via code inspection while fixing and testing #126538:There is no possible way for
main_path=
to be set on the multiprocessing's forkserver.main() call since 2013's 9a76735 for #64145 as shipped in 3.4 (which also introduced the forkserver feature).the
forkserver.main(...)
call is constructed in Lib/multiprocessing/forkserver.py getting its two possible allowed named args fromspawn.get_preparation_data()
inLib/multiprocessing/spawn.py
which was changed to set"init_main_from_name"
in the kwargs dict it returns instead of"main_path"
in the above change. Effectively making themain_path=
handling code dead inforkserver.main
.We should either remove the dead code, or determine if it was intended to support something that has been silently broken when using the forkserver start method for the past 11 years, and if so, add an explicit test for that and adapt it to use
"init_main_from_name"
as the spawn code does.CPython versions tested on:
3.12, 3.13, 3.14, CPython main branch
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: