Le dim. 23 févr. 2020 à 15:06, Nick Coghlan ncoghlan@gmail.com a écrit :
P.S. An aspect of this that looks like it has potentially regressed since Python 3.6 is that whereas Py_NewInterpreter used to consistently print the exception and return NULL on failure [2], there are now several cases where we will instead generate an initialisation status code internally, and exit immediately [3] (even though the parent interpreter is presumably still in a valid state).
Py_NewInterpreter() still displays an error and returns NULL when it can.
Extract of Py_NewInterpreter() code of the master branch:
PyStatus status = new_interpreter(&tstate);
if (_PyStatus_EXCEPTION(status)) {
Py_ExitStatusException(status);
}
Py_ExitStatusException() is only called when new_interpreter() fails to handle a regular Python exception. I added PyStatus at part of the PEP 587 implementation.
In Python 3.6, *many* helper function called by Py_NewInterpreter() called instead Py_FatalError()... which also exits immediately the process. Example:
static void import_init(PyInterpreterState *interp, PyObject *sysmod) { ... /* Import _importlib through its frozen version, _frozen_importlib. */ if (PyImport_ImportFrozenModule("_frozen_importlib") <= 0) { Py_FatalError("Py_Initialize: can't import _frozen_importlib"); } ... }
It would be "nice" to not exit the process if the status is an exception, but that would require to refactor a lot of code :-/ Or a new variant of Py_NewInterpreter() should be added which would return a PyStatus instead. So the caller is free to decide how to handle a PyStatus exception.
Python initialization is quite complex :-/
Victor
Night gathers, and now my watch begins. It shall not end until my death.