Repository navigation
[3.15] gh-159963: Don't hold parent package import locks while a submodule executes (GH-159965) - #160630
Merged
Conversation
…dule executes (pythonGH-159965) Since pythongh-83065 (3.15.0), the first import of pkg.mod kept pkg's module lock until pkg/mod.py had finished executing. Threads that needed only the finished pkg stayed blocked for that long, and concurrent first imports could raise _DeadlockError or a spurious "partially initialized module" ImportError, or hang, with no import cycle involved. Parent packages are now imported, or waited for if another thread is initializing them, before the submodule's module lock is taken, so only that lock is held while the submodule executes. The lock ordering deadlock fixed by pythongh-83065 stays fixed. importlib.import_module() now returns the partially initialized module in a circular import split across threads, as the import statement already did, instead of raising _DeadlockError. That was long-standing behavior rather than part of the 3.15.0 regression. (cherry picked from commit 7159b15) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
miss-islington
requested review from
FFY00,
brettcannon,
ericsnowcurrently,
ncoghlan and
warsaw
as code owners
October 25, 2026 00:06
This was referenced Oct 25, 2026
gpshead
enabled auto-merge (squash)
October 25, 2026 00:07
Documentation build overview
161 files changed ·
|
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.
Since gh-83065 (3.15.0), the first import of pkg.mod kept pkg's module
lock until pkg/mod.py had finished executing. Threads that needed only
the finished pkg stayed blocked for that long, and concurrent first
imports could raise _DeadlockError or a spurious "partially initialized
module" ImportError, or hang, with no import cycle involved.
Parent packages are now imported, or waited for if another thread is
initializing them, before the submodule's module lock is taken, so only
that lock is held while the submodule executes. The lock ordering
deadlock fixed by gh-83065 stays fixed.
importlib.import_module() now returns the partially initialized module
in a circular import split across threads, as the import statement
already did, instead of raising _DeadlockError. That was long-standing
behavior rather than part of the 3.15.0 regression.
(cherry picked from commit 7159b15)
Co-authored-by: Gregory P. Smith 68491+gpshead@users.noreply.github.com
Fixes #159963