gh-113119 fix environment handling in subprocess.Popen when posix_spa… · python/cpython@48c907a · GitHub
Skip to content

Commit 48c907a

Browse files
authored
gh-113119 fix environment handling in subprocess.Popen when posix_spawn is used (#113120)
* Allow posix_spawn to inherit environment form parent environ variable. With this change, posix_spawn call can behave similarly to execv with regards to environments when used in subprocess functions.
1 parent cde1335 commit 48c907a

5 files changed

Lines changed: 21 additions & 10 deletions

File tree

Doc/library/os.rst

Lines changed: 5 additions & 1 deletion

Doc/whatsnew/3.13.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ os
289289
``False`` on Windows.
290290
(Contributed by Serhiy Storchaka in :gh:`59616`)
291291

292+
* :func:`os.posix_spawn` now accepts ``env=None``, which makes the newly spawned
293+
process use the current process environment.
294+
(Contributed by Jakub Kulik in :gh:`113119`.)
295+
292296
pathlib
293297
-------
294298

Lib/subprocess.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,9 +1756,6 @@ def _posix_spawn(self, args, executable, env, restore_signals,
17561756
c2pread, c2pwrite,
17571757
errread, errwrite):
17581758
"""Execute program using os.posix_spawn()."""
1759-
if env is None:
1760-
env = os.environ
1761-
17621759
kwargs = {}
17631760
if restore_signals:
17641761
# See _Py_RestoreSignals() in Python/pylifecycle.c
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:func:`os.posix_spawn` now accepts ``env=None``, which makes the newly spawned
2+
process use the current process environment. Patch by Jakub Kulik.

Modules/posixmodule.c

Lines changed: 10 additions & 6 deletions

0 commit comments

Comments
 (0)