https://github.com/python/cpython/commit/68bbdd902630a5f96ab598a8d6ecacee3c2d5d2e commit: 68bbdd902630a5f96ab598a8d6ecacee3c2d5d2e branch: 3.13 author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com> committer: gpshead <g...@krypto.org> date: 2025-04-06T23:24:24-07:00 summary:
[3.13] gh-129204: Add _PYTHON_SUBPROCESS_USE_POSIX_SPAWN environment knob (GH-132184) (#132191) 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. * fixup NEWS entry --------- (cherry picked from commit 4c5dcc6d8292d5142aff8401cb9b9d18b49c6c89) Signed-off-by: Vincent Fazio <vfa...@gmail.com> Co-authored-by: Vincent Fazio <vfa...@gmail.com> files: A Misc/NEWS.d/next/Library/2025-04-06-19-25-12.gh-issue-129204.sAVFO6.rst M Lib/subprocess.py diff --git a/Lib/subprocess.py b/Lib/subprocess.py index f614c903c8837c..4a9a64e5577989 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -715,6 +715,9 @@ def _use_posix_spawn(): # os.posix_spawn() is not available return False + if ((_env := os.environ.get('_PYTHON_SUBPROCESS_USE_POSIX_SPAWN')) in ('0', '1')): + return bool(int(_env)) + if sys.platform in ('darwin', 'sunos5'): # posix_spawn() is a syscall on both macOS and Solaris, # and properly reports errors diff --git a/Misc/NEWS.d/next/Library/2025-04-06-19-25-12.gh-issue-129204.sAVFO6.rst b/Misc/NEWS.d/next/Library/2025-04-06-19-25-12.gh-issue-129204.sAVFO6.rst new file mode 100644 index 00000000000000..d8994bf760b7bc --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-04-06-19-25-12.gh-issue-129204.sAVFO6.rst @@ -0,0 +1,2 @@ +Introduce new ``_PYTHON_SUBPROCESS_USE_POSIX_SPAWN`` environment variable knob in +:mod:`subprocess` to control the use of :func:`os.posix_spawn`. _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com