]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
GH-83065: Fix import deadlock by implementing hierarchical module locking (GH-137196)
authorGregory P. Smith <68491+gpshead@users.noreply.github.com>
Tue, 28 Apr 2026 08:06:23 +0000 (01:06 -0700)
committerGitHub <noreply@github.com>
Tue, 28 Apr 2026 08:06:23 +0000 (01:06 -0700)
commit9a57179d74c1a20e3188779696c60c8dd812e6fb
tree2589e806cb04477be757fdb6a1a522ab48f812fe
parent29251396a9d4a91255c8f960d22c027887d40543
GH-83065: Fix import deadlock by implementing hierarchical module locking (GH-137196)

Make _find_and_load() acquire the module locks for the full
dotted-name chain (parent before child) when loading a nested module, so
both threads contend on the same first lock and serialise instead of
deadlocking.

When acquiring a parent's lock would itself deadlock with another thread
that is loading that parent (cross-package circular imports), the parent's
lock is skipped and the partially-initialised parent is accepted -- the
same policy _lock_unlock_module() already applies on the existing code
path -- so concurrent circular imports that worked before continue to work.
Doc/whatsnew/3.15.rst
Lib/importlib/_bootstrap.py
Lib/test/test_importlib/test_threaded_import.py
Misc/NEWS.d/next/Core_and_Builtins/2026-04-28-05-59-17.gh-issue-83065.f0UPNE.rst [new file with mode: 0644]