New submission from STINNER Victor <vstin...@redhat.com>:
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 ---------- components: Interpreter Core messages: 337256 nosy: ncoghlan, steve.dower, vstinner priority: normal severity: normal status: open title: Deprecate calling Py_Main() after Py_Initialize()? Add Py_InitializeFromArgv()? versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue36204> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com