[issue46964] The global config should not be stored on each interpreter

STINNER Victor report at bugs.python.org
Wed Mar 23 14:22:07 EDT 2022


STINNER Victor <vstinner at python.org> added the comment:

> thus far we have had no actual use cases for initializing an interpreter
>  with a different config

I don't think that sub-interpreters should have config.install_signal_handlers=1. Same for config.configure_c_stdio=1. Only the main interpreter should handle signals and the configuration of C streams (stdio, stderr, stdio).

I added _PyInterpreterState_SetConfig() to experiment changing config.bytes_warning. But this is no strong need to have an API to change it, so right now, there is still no API for that. If we allow to change it, it would be surprising to change all interpreters at once.

I don't see why config.argv (sys.argv) must be the same in all interpreters. Same for config.module_search_paths (sys.path).

For me, it makes sense to have a per-interpreter value for most PyConfig options.

> * there is no API for creating an interpreter with a different config

There is _Py_NewInterpreter(int isolated_subinterpreter) to set config.config._isolated_interpreter. But since the feature is not "official", it remains a private API.


> currently, every interpreter uses (a copy of) the original PyConfig,
> completely unchanged

Currently, it's possible to call Py_InitializeFromConfig() (or Py_Initialize()) multiple times and it changes the PyConfig of the current interpreter. See the pyinit_core_reconfigure() function. _testembed has an unit test for that: I had to implement this feature. Once, calling the function multiple times and it broke an application. See bpo-34008.

----------

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


More information about the Python-bugs-list mailing list