gh-117953: Always Run Extension Init Func in Main Interpreter First#118157
Merged
ericsnowcurrently merged 18 commits intopython:mainfrom May 7, 2024
Merged
gh-117953: Always Run Extension Init Func in Main Interpreter First#118157ericsnowcurrently merged 18 commits intopython:mainfrom
ericsnowcurrently merged 18 commits intopython:mainfrom
Conversation
8d04512 to
b09c445
Compare
Member
Author
|
FYI, there's a refleak somewhere in here that I'm tracking down. |
zooba
reviewed
May 6, 2024
Member
zooba
left a comment
There was a problem hiding this comment.
Nothing jumps out at me looking like a refleak, unfortunately. Possible the first import is leaking something in the main interpreter and it's not being counted right in the subinterpreter? (Or vice versa)
Python/import.c
Outdated
| * and then continue loading like normal. */ | ||
|
|
||
| PyThreadState *main_tstate = NULL; | ||
| if (!_Py_IsMainInterpreter(tstate->interp)) { |
Member
There was a problem hiding this comment.
Is this necessary if switch_to_main_interpreter is doing the same check?
Member
Author
There was a problem hiding this comment.
It isn't necessary, but I wanted to be explicit about it. I'll see about cleaning that up.
Python/import.c
Outdated
| @@ -1941,15 +2005,73 @@ import_run_extension(PyThreadState *tstate, PyModInitFunction p0, | |||
| if (cached == NULL) { | |||
| goto error; | |||
Member
There was a problem hiding this comment.
Can we do this without switching back?
Member
Author
There was a problem hiding this comment.
Yeah, I noticed that too and have already fixed it locally. 😄
This was referenced May 7, 2024
SonicField
pushed a commit
to SonicField/cpython
that referenced
this pull request
May 8, 2024
…irst (pythongh-118157) This change makes sure all extension/builtin modules have their init function run first by the main interpreter before proceeding with import in the original interpreter (main or otherwise). This means when the import of a single-phase init module fails in an isolated subinterpreter, it won't tie any global state/callbacks to the subinterpreter.
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Jul 8, 2024
pythongh-121503) The change in pythongh-118157 (b2cd54a) should have also updated clear_singlephase_extension() but didn't. We fix that here. Note that clear_singlephase_extension() (AKA _PyImport_ClearExtension()) is only used in tests. (cherry picked from commit 15d48ae) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
ericsnowcurrently
added a commit
that referenced
this pull request
Jul 8, 2024
…ds (gh-121517) The change in gh-118157 (b2cd54a) should have also updated clear_singlephase_extension() but didn't. We fix that here. Note that clear_singlephase_extension() (AKA _PyImport_ClearExtension()) is only used in tests. (cherry picked from commit 15d48ae, AKA gh-121503) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
noahbkim
pushed a commit
to hudson-trading/cpython
that referenced
this pull request
Jul 11, 2024
pythongh-121503) The change in pythongh-118157 (b2cd54a) should have also updated clear_singlephase_extension() but didn't. We fix that here. Note that clear_singlephase_extension() (AKA _PyImport_ClearExtension()) is only used in tests.
estyxx
pushed a commit
to estyxx/cpython
that referenced
this pull request
Jul 17, 2024
pythongh-121503) The change in pythongh-118157 (b2cd54a) should have also updated clear_singlephase_extension() but didn't. We fix that here. Note that clear_singlephase_extension() (AKA _PyImport_ClearExtension()) is only used in tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change makes sure all extension/builtin modules have their init function run first by the main interpreter before proceeding with import in the original interpreter (main or otherwise). This means when the import of a single-phase init module fails in an isolated subinterpreter, it won't tie any global state/callbacks to the subinterpreter.
This supercedes gh-117487.