You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
forkserver slow to start because of __main__ preloading issue #137996
When switching a Python project from the default multiprocessing fork mode to forkserver, I've noticed the processes in the pool got significantly slower to start. Specifying preload modules didn't help.
Debugging internals of multiprocessing showed that most of the time (50 ms in each process in my test) is spent in _fixup_main_from_path(data['init_main_from_path']):
This seemed surprising because __main__ was mentioned in the preload parameter, however I've noticed that forkserver.py tries to populate the main_path parameter from spawn.get_preparation_data():
The end effect is that the __main__ module wasn't preloaded in practice, and every child process had to re-run the main script. Unless I'm missing something, the logic in forkserver.py needs to get main_path from the value of init_main_from_path?
See also issue #126631 and comments, and the associated pull request #135295.
Thanks for pointing this out! The implementation change looks almost identical, and you have a regression test already; do you know what's blocking that change from landing?
Thanks for pointing this out! The implementation change looks almost identical, and you have a regression test already; do you know what's blocking that change from landing?
No worries at all, and yeah, our independent fixes are basically the same, which is nice 🙂
I don't think anything is blocking the change as such, but AIUI the maintainers and core devs in general are overworked and have to prioritise where they spend their time and attention. Before you raised this issue it was a fairly academic fix: it had been broken for many years, seemingly without anyone noticing. It is useful to know it has caused a noticeable performance regression in real-world use!
Activity
XChaitanyaX commentedon Aug 22, 2025
I am new here, is this a good first issue for me to work on?
@emaxx-google can you please share the testcase or the benchmark script.
picnixz commentedon Aug 22, 2025
I don't think so. If you want a good first issue, check for the ones with the
easylabel.pythongh-137996: Fix path to __main__ in forkserver preload logic
emaxx-google commentedon Aug 22, 2025
I have a PR already, but as I'm not deeply familiar with the internals I'm not 100% sure about it.
Use forkserver multiprocessing mode (#305)
duaneg commentedon Sep 1, 2025
See also issue #126631 and comments, and the associated pull request #135295.
emaxx-google commentedon Sep 1, 2025
Thanks for pointing this out! The implementation change looks almost identical, and you have a regression test already; do you know what's blocking that change from landing?
duaneg commentedon Sep 1, 2025
No worries at all, and yeah, our independent fixes are basically the same, which is nice 🙂
I don't think anything is blocking the change as such, but AIUI the maintainers and core devs in general are overworked and have to prioritise where they spend their time and attention. Before you raised this issue it was a fairly academic fix: it had been broken for many years, seemingly without anyone noticing. It is useful to know it has caused a noticeable performance regression in real-world use!
gh-126631: gh-137996: fix pre-loading of `__main__` (GH-135295)
pythongh-126631: pythongh-137996: fix pre-loading of `__main__` (pyth…
[3.13] pythongh-126631: pythongh-137996: fix pre-loading of `__main__` (
[3.13] gh-126631: gh-137996: fix pre-loading of `__main__` (GH-135295) (
pythongh-126631: pythongh-137996: fix pre-loading of `__main__` (pyth…
[3.14] gh-126631: gh-137996: fix pre-loading of `__main__` (GH-135295) (