Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

subprocess.Popen can pass incomplete environment when posix_spawn is used #113119

Closed
Assignees
gpshead
Labels
type-bugAn unexpected behavior, bug, or error
@kulikjak

Description

@kulikjak

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

Linked PRs

Metadata

Metadata

Assignees

Labels

type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp