[Python-Dev] New Python Initialization API

Victor Stinner vstinner at redhat.com
Fri Apr 5 12:22:17 EDT 2019


> > Example of Python initialization enabling the isolated mode::
> >
> >     PyConfig config = PyConfig_INIT;
> >     config.isolated = 1;
>
> Haven't we already used extenal values by this point that should have
> been isolated?

On this specific example, "config.isolated = 1;" ensures that
Py_PreInitialize() is also called internally with
"PyPreConfig.isolated = 1".


> I'd rather have the isolation up front. Or better yet,
> make isolation the default unless you call one of the "FromArgs"
> functions, and then we don't actually need the config setting at all.

While there are supporters of an "isolated Python" (sometimes called
"system python"), the fact that it doesn't exist in any Linux distribution
nor on any other operating system (Windows, macOS, FreeBSD), whereas it's
already doable in Python 3.6 with Py_IsolatedFlag=1 makes me think that
users like the ability to control Python with environment variables and
configuration files.

I would prefer to leave Python as not isolated by default. It's just a
matter of comment line arguments.


> > * The PEP 432 stores ``PYTHONCASEOK`` into the config. Do we need
> >   to add something for that into ``PyConfig``? How would it be exposed
> >   at the Python level for ``importlib``? Passed as an argument to
> >   ``importlib._bootstrap._setup()`` maybe? It can be added later if
> >   needed.
>
> Could we convert it into an xoption? It's very rarely used, to my knowledge.

The first question is if there is any need for an embedder to change
this option. Currently, importlib._bootstrap_external._install() reads
the environment variable and it's the only way to control the option.

... By the way, importlib reads PYTHONCASEOK environment varaible even
if isolated mode is enabled (sys.flags.isolated is equal to 1). Is it
a bug? :-)

Victor


More information about the Python-Dev mailing list