cpython icon indicating copy to clipboard operation
cpython copied to clipboard

[3.10] gh-98552: Fix preloading '__main__' with forkserver being broken

Open aggieNick02 opened this issue 2 years ago • 3 comments

This has been broken 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.

  • Issue: gh-98552

aggieNick02 avatar Oct 31 '22 20:10 aggieNick02

All commit authors signed the Contributor License Agreement.
CLA signed

cpython-cla-bot[bot] avatar Oct 31 '22 20:10 cpython-cla-bot[bot]

Hey @aggieNick02, thanks for this fix. It looks promising. However, the change should go against the main branch and not 3.10 as the issue needs fixing in 3.12 and 3.11 as well.

I realize we weren't sufficiently explicit about this in the past so I updated the devguide to explain what's up: https://devguide.python.org/getting-started/pull-request-lifecycle/#good-prs

ambv avatar Nov 11 '22 16:11 ambv

Ah, ok. Thanks for updating the instructions to make it clear. I wanted to do whatever gave it the best chance at making it into 3.10 (to be part of Ubuntu 22.04 LTS). I'll make a new PR against main shortly. Thanks!

aggieNick02 avatar Nov 11 '22 17:11 aggieNick02

Alright, I put this against main. In the process realized I wasn't passing down the raise_exception option in one place. So I added a test that would catch that and fixed it. https://github.com/python/cpython/pull/99515.

aggieNick02 avatar Nov 15 '22 19:11 aggieNick02

Closing since obsoleted by new PR against correct branch.

aggieNick02 avatar Nov 15 '22 19:11 aggieNick02