Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
Subprocess created withposix_spawn can have different environment when compared to a process created with stardardfork/exec.
The reason is thatposix_spawn usesos.environ (when no env was given), which is not affected byos.putenv andos.unsetenv. This is different fromexecv, which uses process environment (available throughenviron).
This can be easily reproduced withtest_putenv_unsetenv modified to callsubprocess.run withclose_fds=False (which makes it use theposix_spawn call):
importsubprocessimportsysimportosname="PYTHONTESTVAR"value="testvalue"code=f'import os; print(repr(os.environ.get({name!r})))'os.putenv(name,value)proc=subprocess.run([sys.executable,'-c',code],check=True,stdout=subprocess.PIPE,text=True,close_fds=False)assertproc.stdout.rstrip()==repr(value)os.unsetenv(name)proc=subprocess.run([sys.executable,'-c',code],check=True,stdout=subprocess.PIPE,text=True,close_fds=False)assertproc.stdout.rstrip()==repr(None)
I found it when I patched Python with#113118 (on Solaris, but this is pretty platform independent, I think).
CPython versions tested on:
3.9, 3.11
Operating systems tested on:
Other