[New-bugs-announce] [issue35239] _PySys_EndInit() doesn't copy main interpreter configuration

STINNER Victor report at bugs.python.org
Tue Nov 13 18:08:32 EST 2018


New submission from STINNER Victor <vstinner at redhat.com>:

Extract of _PySys_EndInit():

SET_SYS_FROM_STRING_BORROW("path", config->module_search_path);

sys.path is initialized from _PyMainInterpreterConfig.module_search_path object: the list of strings is not copied. As a consequence, when sys.path is modified, _PyMainInterpreterConfig is modified as well. For example, "import site" modifies sys.path.

I dislike this behavior. I prefer to see _PyMainInterpreterConfig as "constant": a snapshot of the configuration used to startup Python.

A side effect is that Py_NewInterpreter() copies the modified configuration, whereas starting from the "original" configuration. For the specific case of Py_NewInterpreter(), I'm not sure of what is the expected behavior... Py_NewInterpreter() imports the "site" module again, so it should reapply the same sys.path change.

Note: I found this bug while working on better tests for global, core and main configurations: https://github.com/python/cpython/pull/10524

----------
components: Interpreter Core
messages: 329872
nosy: eric.snow, ncoghlan, vstinner
priority: normal
severity: normal
status: open
title: _PySys_EndInit() doesn't copy main interpreter configuration
versions: Python 3.7, Python 3.8

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


More information about the New-bugs-announce mailing list