Skip to content
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

Bug 916566 returnproc migration #1251

Merged
merged 8 commits into from Feb 7, 2024

Conversation

zmedico
Copy link
Member

@zmedico zmedico commented Feb 4, 2024

Now includes a 3.12-dev ci job patched to set the multiprocessing start method to spawn, which took 7m 11s compared to 4m 16s for the 3.12-dev fork ci job.

Bug: https://bugs.gentoo.org/916566

@zmedico zmedico marked this pull request as draft February 4, 2024 06:05
@zmedico zmedico force-pushed the bug_916566_returnproc_migration branch from fff7884 to fec465c Compare February 5, 2024 01:12
@zmedico zmedico force-pushed the bug_916566_returnproc_migration branch 5 times, most recently from 3e51fb6 to 933c540 Compare February 5, 2024 06:16
@zmedico zmedico marked this pull request as ready for review February 5, 2024 06:24
@zmedico zmedico force-pushed the bug_916566_returnproc_migration branch 6 times, most recently from 3bf3797 to c2556b1 Compare February 6, 2024 01:41
@zmedico zmedico marked this pull request as draft February 6, 2024 02:32
@zmedico zmedico force-pushed the bug_916566_returnproc_migration branch 7 times, most recently from 89a84db to 92e7e22 Compare February 6, 2024 08:01
@zmedico zmedico marked this pull request as ready for review February 6, 2024 08:19
@zmedico zmedico force-pushed the bug_916566_returnproc_migration branch from 92e7e22 to c789c7e Compare February 6, 2024 19:25
@zmedico zmedico force-pushed the bug_916566_returnproc_migration branch from c789c7e to 7bdb23c Compare February 6, 2024 19:29
Convert _send_fd_pipes BrokenPipeError to asyncio.CancelledError,
in order to gracefully handle a concurrently terminated child
process as in testAsynchronousLockWaitCancel. Even if the child
terminated abnormally, then there is no harm in suppressing the
exception here, since the child error should have gone to stderr.

Bug: https://bugs.gentoo.org/923852
Signed-off-by: Zac Medico <zmedico@gentoo.org>
@zmedico zmedico force-pushed the bug_916566_returnproc_migration branch from 7bdb23c to 97f27d6 Compare February 7, 2024 00:37
@thesamesam
Copy link
Member

Now includes a 3.12-dev ci job patched to set the multiprocessing start method to spawn, which took 7m 11s compared to 4m 16s for the 3.12-dev fork ci job.

I'm really curious about this part -- spawn should be quite a bit faster where posix_spawn is eligible at least. There's python/cpython#114467 and python/cpython#113117 which are two cases it's not used where it could be.

lib/portage/package/ebuild/doebuild.py Outdated Show resolved Hide resolved
lib/portage/util/futures/executor/fork.py Outdated Show resolved Hide resolved
Use the AsyncFunction create_pipe=False parameter to avoid issues
in the pipe code triggered with the "spawn" multiprocessing start
method when spawn uses multiprocessing.Process (bug 916566), since
these jobs should inherit stdio streams and run in the foreground
with no log. Also fix RetryForkExecutorTestCase to avoid pickling
issues.

Bug: https://bugs.gentoo.org/923854
Signed-off-by: Zac Medico <zmedico@gentoo.org>
Use multiprocessing.Process for returnproc, so that
fork will stop being used when python makes "spawn"
the default multiprocessing start method.

Continue to use _start_fork when returnproc is not
enabled, for backward compatibility. Ultimately,
it can be removed at the same time as the returnpid
parameter.

The _setup_pipes_after_fork wrapper prevents a
"Bad file descriptor" error by making fd_pipes
inheritable on exec for bug 923755. ForkProcess
does not handle this because its target function
does not necessarily exec.

Bug: https://bugs.gentoo.org/916566
Bug: https://bugs.gentoo.org/923755
Signed-off-by: Zac Medico <zmedico@gentoo.org>
@zmedico zmedico force-pushed the bug_916566_returnproc_migration branch from 97f27d6 to 1cd832d Compare February 7, 2024 00:49
Raise NotImplementedError if returnproc is enabled for anything
other than the "depend" phase, since corresponding returnpid
support has long been deprecated.

Bug: https://bugs.gentoo.org/916566
Signed-off-by: Zac Medico <zmedico@gentoo.org>
Bug: https://bugs.gentoo.org/916566
Signed-off-by: Zac Medico <zmedico@gentoo.org>
Bug: https://bugs.gentoo.org/916566
Signed-off-by: Zac Medico <zmedico@gentoo.org>
All internal returnpid consumers have been migrated to
use the new returnproc parameter instead.

Bug: https://bugs.gentoo.org/916566
Signed-off-by: Zac Medico <zmedico@gentoo.org>
This essentially completes the implementation of bug 916566,
eliminating os.fork() usage when "spawn" becomes the default
multiprocessing start method.

Bug: https://bugs.gentoo.org/916566
Signed-off-by: Zac Medico <zmedico@gentoo.org>
@zmedico zmedico force-pushed the bug_916566_returnproc_migration branch from 1cd832d to 3e10368 Compare February 7, 2024 00:56
@zmedico
Copy link
Member Author

zmedico commented Feb 7, 2024

Now includes a 3.12-dev ci job patched to set the multiprocessing start method to spawn, which took 7m 11s compared to 4m 16s for the 3.12-dev fork ci job.

I'm really curious about this part -- spawn should be quite a bit faster where posix_spawn is eligible at least. There's python/cpython#114467 and python/cpython#113117 which are two cases it's not used where it could be.

The issue is that there is a lot of back-and-forth between the parent and child process during the child process setup. The parent needs to pickle any referenced objects and send them. ForkProcess needs to send fd_pipes just before the target function is called.

It's slow for unit tests where a disproportionate number of processes are created and destroyed, but for normal operation the difference should be pretty negligible.

@gentoo-bot gentoo-bot merged commit 3e10368 into gentoo:master Feb 7, 2024
12 checks passed
@zmedico zmedico deleted the bug_916566_returnproc_migration branch February 7, 2024 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants