[New-bugs-announce] [issue39376] Avoid modifying the process global environment (not thread safe)

Gregory P. Smith report at bugs.python.org
Fri Jan 17 19:47:44 EST 2020


New submission from Gregory P. Smith <greg at krypto.org>:

For more context, see https://bugs.python.org/issue39375 which seeks to document the existing caveats.

POSIX lacks any APIs to access the process global environment in a thread safe manner.  Given this, we could _consider_ preventing os.putenv() and os.environ[x] = y assignment from actually modifying the process global environment.  They'd save their changes in our local os.environ underlying dict, set a flag that it was modified, but not modify the global.

This would be a visible behavior change and break _some_ class of code. :/

Our stdlib codepaths that launch a new process on POSIX could be modified to to always pass our a newly constructed envp from os.environ to exec/spawn APIs.  The os.system() API would need to stop using the POSIX system() API call in order for that to work.

Downside API breakage: Extension module modifications to the environment would not be picked up by Python interpreter launched subprocesses.  How much of a problem would that be in practice?

We may decide to close this as infeasible and just stick with the documentation of the sorry state of POSIX and not attempt to offer any safe non-crash-possible workarounds.

----------
components: Interpreter Core
messages: 360222
nosy: gregory.p.smith
priority: normal
severity: normal
stage: needs patch
status: open
title: Avoid modifying the process global environment (not thread safe)
type: crash
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39376>
_______________________________________


More information about the New-bugs-announce mailing list