Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c5dcc6

Browse files
authored
gh-129204: Add _PYTHON_SUBPROCESS_USE_POSIX_SPAWN environment knob (GH-132184)
* Add _PYTHON_SUBPROCESS_USE_POSIX_SPAWN environment knob Add support for disabling the use of `posix_spawn` via a variable in the process environment. While it was previously possible to toggle this by modifying the value of `subprocess._USE_POSIX_SPAWN`, this required either patching CPython or modifying it within the interpreter instance which is not always possible, such as when running applications or scripts not under a user's control. Signed-off-by: Vincent Fazio <[email protected]> * fixup NEWS entry --------- Signed-off-by: Vincent Fazio <[email protected]>
1 parent 6eaa4ae commit 4c5dcc6

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Lib/subprocess.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ def _use_posix_spawn():
715715
# os.posix_spawn() is not available
716716
return False
717717

718+
if ((_env := os.environ.get('_PYTHON_SUBPROCESS_USE_POSIX_SPAWN')) in ('0', '1')):
719+
return bool(int(_env))
720+
718721
if sys.platform in ('darwin', 'sunos5'):
719722
# posix_spawn() is a syscall on both macOS and Solaris,
720723
# and properly reports errors
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Introduce new ``_PYTHON_SUBPROCESS_USE_POSIX_SPAWN`` environment variable knob in
2+
:mod:`subprocess` to control the use of :func:`os.posix_spawn`.

0 commit comments

Comments
 (0)