Skip to content

gh-98552: Fix preloading '__main__' with forkserver being broken for a #99515

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aggieNick02
Copy link

@aggieNick02 aggieNick02 commented Nov 15, 2022

long time (9 years).

We do this by using spawn.get_preparation_data() and then using the values in that dictionary appropriately. This lets us also fix the setting of sys.path (which never worked) and other minor properties of the forkserver process.

While updating the test to verify these fixes, we also discovered that forkserver was not flushing stdout/stderr before it forked to create a new process. This caused the updated test to fail because unflushed output in the forkserver would then be printed by the forked process as well. This is now fixed too.

…n for a

long time (9 years).

We do this by using spawn.get_preparation_data() and then using the
values in that dictionary appropriately. This lets us also fix the
setting of sys.path (which never worked) and other minor properties of
the forkserver process.

While updating the test to verify these fixes, we also discovered that
forkserver was not flushing stdout/stderr before it forked to create a
new process. This caused the updated test to fail because unflushed
output in the forkserver would then be printed by the forked process as
well. This is now fixed too.
@aggieNick02
Copy link
Author

One minor thing I noticed incase @pitrou remembers from several years ago. In Lib/test/mp_preload.py, the file begins with an import multiprocessing then multiprocessing.Lock() . Any idea what purpose the call to multiprocessing.Lock() serves? Some sort of required initialization?

@pitrou
Copy link
Member

pitrou commented Nov 16, 2022

@aggieNick02 I suppose it's a simple check that multiprocessing is usable from a preloaded module?

@aggieNick02
Copy link
Author

@aggieNick02 I suppose it's a simple check that multiprocessing is usable from a preloaded module?

Ah ok, thanks!

@brettcannon brettcannon removed their request for review November 16, 2022 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants