New submission from Nick Coghlan <ncogh...@gmail.com>:

In the current documentation, Py_Main is listed as a regular C API function: 
https://docs.python.org/3/c-api/veryhigh.html#c.Py_Main

We also didn't add Py_Main() to 
https://docs.python.org/3/c-api/init.html#before-python-initialization when we 
did the review for "Functions which are safe to call before Py_Initialize()".

If it truly is a regular C API function, then this suggests that Py_Main() 
should be called *after* Py_Initialize().

However, Py_Main() has historically called Py_Initialize() *itself*, and 
generally assumes it has total control over management of the current process - 
it doesn't expect to be sharing the current process with an embedding 
application.

In Python 3.7, Py_Main() was changed to call _Py_InitializeCore() and 
_Py_InitializeMainInterpreter() as separate steps, allowing it to detect cases 
where an embedding application had already called Py_Initialize(), meaning that 
Py_Main()'s config setting changes wouldn't be applied.

In effect, we've converted a silent failure (settings not read and applied as 
expected) into a noisy one (attempting to call Py_Main() in an already 
initialised interpreter).

(The test suite is silent on the matter, since the idea of an embedding 
application calling Py_Initialize() before calling Py_Main() never even 
occurred to us)

So the question is, what should we do about this for Python 3.7:

1. Treat it as a regression, try to replicate the old behaviour of partially 
(but not completely) ignoring the config settings read by Py_Main()
2. Treat it as a regression, but don't try to replicate the old 
config-settings-are-partially-applied behaviour - just ignore the settings read 
by Py_Main() completely
3. Treat it as a long standing documentation error, update the docs to make it 
clear that Py_Main() expects to handle calling Py_Initialize() itself, and 
update the Python 3.7 porting guide accordingly

----------
messages: 320758
nosy: eric.snow, ncoghlan, vstinner
priority: normal
severity: normal
stage: test needed
status: open
title: Do we support calling Py_Main() after Py_Initialize()?
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to