Skip to content

Support the macOS-only POSIX_SPAWN_CLOEXEC_DEFAULT flag and posix_spawn_file_actions_addinherit_np() in os.posix_spawn #109154

Open
@mrpippy

Description

@mrpippy

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, where close_fds defaulting to True means that posix_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 use posix_spawn() when close_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 to os.posix_spawn() and os.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() in subprocess.
#86904 proposed changing close_fds to default to False, so posix_spawn() could be used more often

Metadata

Metadata

Labels

3.13bugs and security fixesOS-mactype-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions