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

gh-104372: Drop the GIL around the vfork() call. #104782

Merged
merged 5 commits into from
May 25, 2023

Conversation

gpshead
Copy link
Member

@gpshead gpshead commented May 23, 2023

On Linux where the subprocess module can use the vfork syscall for faster spawning, prevent the parent process from blocking other threads by dropping the GIL while it waits for the vfork'ed child process exec outcome. This prevents spawning a binary from a slow filesystem from blocking the rest of the application.

Fixes #104372.

On Linux where the `subprocess` module can use the `vfork` syscall for
faster spawning, prevent the parent process from blocking other threads
by dropping the GIL while it waits for the vfork'ed child process `exec`
outcome.  This prevents spawning a binary from a slow filesystem from
blocking the rest of the application.

Fixes python#104372.
@gpshead
Copy link
Member Author

gpshead commented May 23, 2023

This PR is preferred over #104515 as it does not rely on undefined behavior magic cross-process address space sharing shenanigans.

Pre-requisites: #104518 + #104697 to make the post vfork code safe for use without the GIL.

@gpshead gpshead added needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels May 23, 2023
@cpython-cla-bot
Copy link

cpython-cla-bot bot commented May 24, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@gpshead gpshead requested review from Yhg1s and vstinner May 24, 2023 08:13
@gpshead gpshead marked this pull request as ready for review May 24, 2023 08:14
Modules/_posixsubprocess.c Show resolved Hide resolved
@gpshead gpshead enabled auto-merge (squash) May 25, 2023 19:53
@gpshead gpshead merged commit d086792 into python:main May 25, 2023
20 of 21 checks passed
@miss-islington
Copy link
Contributor

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @gpshead, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker d08679212d9af52dd074cd4a6abb440edb944c9c 3.11

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 25, 2023
On Linux where the `subprocess` module can use the `vfork` syscall for
faster spawning, prevent the parent process from blocking other threads
by dropping the GIL while it waits for the vfork'ed child process `exec`
outcome.  This prevents spawning a binary from a slow filesystem from
blocking the rest of the application.

Fixes pythonGH-104372.
(cherry picked from commit d086792)

Co-authored-by: Gregory P. Smith <gps@python.org>
@bedevere-bot
Copy link

GH-104942 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 bug and security fixes label May 25, 2023
@gpshead gpshead deleted the subprocess-drop-gil-before-vfork branch May 25, 2023 20:15
gpshead added a commit that referenced this pull request May 25, 2023
…104942)

gh-104372: Drop the GIL around the vfork() call. (GH-104782)

On Linux where the `subprocess` module can use the `vfork` syscall for
faster spawning, prevent the parent process from blocking other threads
by dropping the GIL while it waits for the vfork'ed child process `exec`
outcome.  This prevents spawning a binary from a slow filesystem from
blocking the rest of the application.

Fixes GH-104372.
(cherry picked from commit d086792)

Co-authored-by: Gregory P. Smith <gps@python.org>
gpshead added a commit to gpshead/cpython that referenced this pull request May 26, 2023
On Linux where the `subprocess` module can use the `vfork` syscall for
faster spawning, prevent the parent process from blocking other threads
by dropping the GIL while it waits for the vfork'ed child process `exec`
outcome.  This prevents spawning a binary from a slow filesystem from
blocking the rest of the application.

Fixes python#104372.

(cherry picked from commit d086792)
@bedevere-bot
Copy link

GH-104958 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label May 26, 2023
gpshead added a commit that referenced this pull request Sep 1, 2023
…04958)

gh-104372: Drop the GIL around the vfork() call. (#104782)

On Linux where the `subprocess` module can use the `vfork` syscall for
faster spawning, prevent the parent process from blocking other threads
by dropping the GIL while it waits for the vfork'ed child process `exec`
outcome.  This prevents spawning a binary from a slow filesystem from
blocking the rest of the application.

Fixes #104372.

(cherry picked from commit d086792)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

subprocess can block all Python threads when using vfork() until the child process exec() succeeds or fails.
4 participants