[3.7] bpo-34247: Fix Python 3.7 initialization#8659
Conversation
* -X dev: it is now possible to override the memory allocator using PYTHONMALLOC even if the developer mode is enabled. * Add _Py_InitializeFromConfig() * Add _Py_Initialize_ReadEnvVars() to set global configuration variables from environment variables * Fix the code to initialize Python: Py_Initialize() now also reads environment variables * _Py_InitializeCore() can now be called twice: the second call only replaces the configuration. * Write unit tests on Py_Initialize() and the different ways to configure Python * The isolated mode now always sets Py_IgnoreEnvironmentFlag and Py_NoUserSiteDirectory to 1. * pymain_read_conf() now saves/restores the configuration if the encoding changed
Restore legacy_windows_fs_encoding change.
The symbol is not exported.
Replace _Py_InitializeEx_Private() with _Py_InitializeFromConfig(). The _Py_InitializeEx_Private() function has been removed.
|
@ronaldoussoren: I will merge this change in two weeks if I don't hear anything from you, since I know feel guilty of having introducing regressions in Python 3.7. This change adds new tests which is something very new for this part of the C API. The tests make me confident in my change :-) They helped me to fix bugs in this PR :-) |
Sorry, something went wrong.
|
This PR backports the best enhancements from the master branch without backporting everything, since I made too many changes in the master. And it seems that master is going to get much more changes, according to the PEP 432 discussion on python-dev. So I prefer to implement the minimum changes for 3.7 just to handle environment variables and to have working unit tests. |
Sorry, something went wrong.
|
Seeing if I can make the backport-pr bot happy by updating the PR title to refer to itself :) (Update: I don't think the title edit triggered any of the bots to re-run, not even the backport-pr bot) |
Sorry, something went wrong.
ncoghlan
left a comment
There was a problem hiding this comment.
This is looking pretty good to me - just a few readability/debuggability comments inline.
Sorry, something went wrong.
|
After reviewing the change, I slightly reworded the section in the commit message about |
Sorry, something went wrong.
|
bedevere/backport-pr status is not required and does not block merging. You'll notice the "Squash and merge" button is still enabled. |
Sorry, something went wrong.
|
And the PR needs to start with |
Sorry, something went wrong.
|
Ah, cool - that means the self-reference is a valid workaround, I just missed that the prefix was missing as well. |
Sorry, something went wrong.
|
I've deployed the latest change in bedevere, so now it is only looking for the |
Sorry, something went wrong.
* Remove a redundant #ifndef Py_LIMITED_API in pylifecycle.h. * Rename _Py_Initialize_ReadEnvVars() to _Py_Initialize_ReadEnvVarsNoAlloc(). * Change _Py_InitializeCore_impl() error message
vstinner
left a comment
There was a problem hiding this comment.
Sorry, something went wrong.
ncoghlan
left a comment
There was a problem hiding this comment.
+1 for going ahead with this version.
We may want to tweak the porting note in What's New, as I believe this may read more environment variables at init time than the interpreter did previously, so embedding applications that want more complete control may now need to set Py_IgnoreEnvironmentFlag when they could previously get by without it.
Sorry, something went wrong.
|
@vstinner: Please replace |
Sorry, something went wrong.

PYTHONMALLOC even if the developer mode is enabled.
variables from environment variables
environment variables
and subsequent calls only replace the configuration, they don't
recreate the main interpreter
configure Python
Py_NoUserSiteDirectory to 1.
if the encoding changed
https://bugs.python.org/issue34247