-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
Support the macOS-only POSIX_SPAWN_CLOEXEC_DEFAULT flag and posix_spawn_file_actions_addinherit_np() in os.posix_spawn #109154
Comments
also @vstinner |
Using this API looks useful on first glance. There's no need to change the API of subprocess for this though, |
@gpshead: a quick API design question: there's two ways to implement this for macOS:
The disadvantage of 1 is that this makes part of the API non-portable. The disadvantage of 2 is more house keeping in C code. BTW. Both libc and macOS also have |
Hi, I started looking into |
I like adding a new platform specific flag to the We should not add a new As for macOS version, I'd be conservative and use 11+ as the version cutoff before we try to use this non-posix addition - Apple doesn't support versions older than 11 anyways AFAICT. |
Emulating CLOSEFROM is easy enough and has the advantage of matching the Linux interface. For better or worse there will be a lot of code that is developed on Linux and requires extra work to run on macOS (e.g. there are still complaints about the start_method being different on macOS even if there are good reasons for that).
Except where we don't expose platforms directly (think of the All in all I think it would be better to pick my option 3: expose both the native functionality and emulate the linux API unless it turns out to be non-trivial to do the latter.
I agree with not changing the interface of subprocess.Popen for this. The new parameter is needed for
The API is supported on macOS 10.7 or later, I can test on 10.9 to check if works there. If it does we get a consistent behaviour on all platforms supported by our installer |
If you're willing to write |
Feature or enhancement
Proposal:
macOS supports a non-standard
posix_spawn()
flag,POSIX_SPAWN_CLOEXEC_DEFAULT
, which makes "only file descriptors explicitly created by the file_actions argument available in the spawned process; all of the other file descriptors are automatically closed in the spawned process."This would be useful for
subprocess
, whereclose_fds
defaulting to True means thatposix_spawn()
is not used by default.POSIX_SPAWN_CLOEXEC_DEFAULT
combined with (the also non-standard)posix_spawn_file_actions_addinherit_np()
would provide a correct way to useposix_spawn()
whenclose_fds=True
.A Chromium bug indicates that
POSIX_SPAWN_CLOEXEC_DEFAULT
was added in OS X 10.7 but causes kernel panics there, for safety this should probably only be used on OS X 10.8 and later.This could be added as a
cloexec_default=False
argument toos.posix_spawn()
andos.posix_spawnp()
.Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
#79718 was the original issue for using
os.posix_spawn()
insubprocess
.#86904 proposed changing
close_fds
to default to False, soposix_spawn()
could be used more oftenThe text was updated successfully, but these errors were encountered: