This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients docs@python, eryksun, gregory.p.smith
Date 2020-01-22.08:11:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> no need to remove that message.  

I was discussing the wrong API. It's not directly relevant that Windows API functions that access the process environment are protected by the PEB lock. Python primarily uses [_w]environ, a copy of the process environment that's managed by the C runtime library (ucrt). os.putenv modifies this environment via _wputenv. (Ultimately this syncs with the process environment by calling SetEnvironmentVariableW.)

Functions that modify and read ucrt's environment are protected by a lock. But there's still a concern if multithreaded code reads or modifies [_w]environ concurrent to a _[w]putenv call. Also, [_w]getenv returns a pointer to the value in [_w]environ, so it has the same problem. A significant difference, however, is that _[w]putenv in ucrt is not POSIX compliant, since it copies the caller's string. Also, ucrt has safer [_w]getenv_s and _[w]dupenv_s functions that return a copy.
Date User Action Args
2020-01-22 08:11:06eryksunsetrecipients: + eryksun, gregory.p.smith, docs@python
2020-01-22 08:11:06eryksunsetmessageid: <>
2020-01-22 08:11:06eryksunlinkissue39375 messages
2020-01-22 08:11:06eryksuncreate