Skip to content

gh-159963: Don't hold parent package import locks while a submodule executes - #159965

Draft
gpshead wants to merge 4 commits into
python:mainfrom
gpshead:import-parent-locks-regression
Draft

gpshead wants to merge 4 commits into
python:mainfrom
gpshead:import-parent-locks-regression

Conversation

@gpshead

@gpshead gpshead commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Since gh-83065, the first import of pkg.mod kept pkg's module lock until pkg/mod.py had finished executing. This shipped in 3.15.0. Threads needing only the finished pkg were 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, before the submodule's lock is taken, and only that lock is held while it executes. The original gh-83065 deadlock stays fixed.

importlib.import_module() now returns the partially initialized module in a cross-thread circular import, as the import statement already did, instead of raising _DeadlockError.


leaving draft for now while further tests are run - and i want to do a pass over the docs and comments text and such before others take a deep look without knowing that.

authored using Claude.

…dule executes

Since pythongh-83065, the first import of pkg.mod kept pkg's module lock
until pkg/mod.py had finished executing.  Threads needing only the
finished pkg were 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, before the submodule's
lock is taken, and only that lock is held while it executes.  The
original pythongh-83065 deadlock stays fixed.

importlib.import_module() now returns the partially initialized module
in a cross-thread circular import, as the import statement already did,
instead of raising _DeadlockError.
@read-the-docs-community

read-the-docs-community Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35310738 | 📁 Comparing 5d2a312 against main (80040b6)

  🔍 Preview build  

45 files changed · + 1 added · ± 44 modified

+ Added

± Modified

Address review: shorten the NEWS entry per the updated devguide guidance,
reword the What's New entry, and trim the _resolve_parents() docstring and
the parent fallback comment in _find_and_load_unlocked().
Comment thread Doc/whatsnew/3.15.rst Outdated
Comment thread Lib/importlib/_bootstrap.py Outdated
Comment thread Lib/importlib/_bootstrap.py Outdated
Comment thread Lib/importlib/_bootstrap.py
Comment thread Doc/whatsnew/3.15.rst Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.15 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant