[issue39406] Implement os.putenv() with setenv() if available
Eryk Sun
report at bugs.python.org
Tue Jan 21 05:57:50 EST 2020
Eryk Sun <eryksun at gmail.com> added the comment:
> Maybe use SetEnvironmentVariable() on Windows?
`_wputenv` keeps Python's copy of the environment block in sync with CRT's copy, which in turn calls `SetEnvironmentVariableW` to sync with process environment block. The CRT's copy of the environment excludes and disallows variable names that start with "=". Because the interpreter initializes `os.environ` from the CRT environment, Python has never included or allowed 'hidden' variables such as "=C:".
Switching to calling `SetEnvironmentVariableW` directly won't affect `os.system` and `os.spawnv[e]`, since the CRT calls `CreateProcessW` without overriding the process environment. However, have you considered the consequences for extension modules and embedding applications that use the CRT environment (e.g. `getenv`, `_wgetenv`) if the interpreter stops syncing with it?
The concern that `[_w]putenv` doesn't copy the string does not apply to Windows.
----------
nosy: +eryksun
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39406>
_______________________________________
More information about the Python-bugs-list
mailing list