FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.15] gh-159963: Don't hold parent package import locks while a submodule executes (GH-159965) by miss-islington · Pull Request #160630 · python/cpython · GitHub

Repository navigation

[3.15] gh-159963: Don't hold parent package import locks while a submodule executes (GH-159965) - #160630

Merged
gpshead merged 2 commits into
python:3.15from
miss-islington:backport-7159b15-3.15
Oct 25, 2026
Merged

gpshead merged 2 commits into
python:3.15from
miss-islington:backport-7159b15-3.15

Conversation

miss-islington commented Oct 25, 2026 •
edited by gpshead
Loading

Copy link
Copy Markdown
Contributor

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

…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>
gpshead requested a review from AA-Turner as a code owner October 25, 2026 00:27
gpshead removed the sprint label Oct 25, 2026

Copy link
Copy Markdown

gpshead merged commit 3255d5d into python:3.15 Oct 25, 2026
56 checks passed
github-project-automation Bot moved this from Todo to Done in Sprint Oct 25, 2026
miss-islington deleted the backport-7159b15-3.15 branch October 25, 2026 00:56
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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL