[issue35239] _PySys_EndInit() doesn't copy main interpreter configuration

STINNER Victor report at bugs.python.org
Wed Nov 14 07:59:36 EST 2018


STINNER Victor <vstinner at redhat.com> added the comment:

Python has 3 kind of configurations:

* global configuration variables like Py_VerboseFlag
* core configuration: _PyCoreConfig
* main interpreter configuration: _PyMainInterpreterConfig

I tried to keep them consistency. Yesterday, I rewrote test_embed.InitConfigTests to really test that these 3 configurations are consistent... And I found multiple bugs :-) (I fixed them as well)

sys.flags is immutable, but some configurations are only used to "initialize" Python which can then be modified. sys.path is a good example.

I don't think that we can ensure that sys.path is always consistent with the main/core configuration (module_search_paths). It's possible to write "sys.path = ['/new/path']". There is no machinery at the module level to call a function when a sys module is *replaced*.

I propose to try to ensure that the configuration is not modified during Python lifecycle, and so that sys.path is a *copy* of the configuration. Same rationale for sys.warnoptions (list) and sys._xoptions (dict).

Attached PR 10532 implements this solution: copy lists and dicts.

----------

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


More information about the Python-bugs-list mailing list