Message337256
If Py_Main() is called after Py_Initialize(), the configuration read by Py_Main() is mostly ignored to only keep the configuration read and writen by Py_Initialize(). Only sys.argv and the internal "path configuration" are updated. Problem: in this case, "core_config" is copied into PyInterpreter.core_config anyway, creating an inconsistency.
Technically, Py_Main() could be smarter and only partially update PyInterpreterState.core_config, but... is it really worth it?
Py_Main() can get many options from the command line arguments. For example, if "-X dev" is passed on the command line, the memory allocator should be "debug". Problem: Py_Initialize() already allocated a lot of memory, and it is no longer possible to change the memory allocator.
I propose to start to emit a deprecation warning when Py_Main() is called after Py_Initialize(): calling Py_Main() alone is just fine.
See bpo-34008: "Do we support calling Py_Main() after Py_Initialize()?". I had to fix a regression in Python 3.7 to fix the application called "fontforge".
Pseudo-code of fontforge:
Py_Initialize()
for file in files:
PyRun_SimpleFileEx(file)
Py_Main(arg, argv)
Py_Finalize()
https://github.com/fontforge/fontforge/blob/cec4a984abb41419bf92fc58e5de0170404f0303/fontforge/python.c
Maybe we need to add a new "initialization" API which accepts (argc, argv)? I implemented such function in bpo-36142, but added functions are private:
* _PyPreConfig_ReadFromArgv()
* _PyCoreConfig_ReadFromArgv()
This issue has been discussed at:
https://discuss.python.org/t/adding-char-based-apis-for-unix/916/22 |
|
Date |
User |
Action |
Args |
2019-03-06 01:08:45 | vstinner | set | recipients:
+ vstinner, ncoghlan, steve.dower |
2019-03-06 01:08:45 | vstinner | set | messageid: <1551834525.71.0.299851927567.issue36204@roundup.psfhosted.org> |
2019-03-06 01:08:45 | vstinner | link | issue36204 messages |
2019-03-06 01:08:45 | vstinner | create | |
|