Python os.putenv() does not update os.environ: os.environ.get('PUT') is None while child processes see PUT=1
os.putenv and os.unsetenv change the process's C-level environment, which child processes inherit, but they do not update the os.environ mapping. After os.putenv('PUT', '1'), os.environ.get('PUT') returns None while subprocess.run(['sh', '-c', 'echo [$PUT]']) prints [1]; conversely, after os.environ['Z'] = '1'; os.unsetenv('Z'), os.environ still reports '1' but the child sees nothing. Code that mixes the two (often copied from C or older Python examples) ends up with Python and its children disagreeing about the environment. Fix: modify the environment only through os.environ (assignment, del, pop), which calls putenv/unsetenv for you, or pass env=dict(os.environ, KEY=value) to subprocess. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7 (macOS).