SIGN IN SIGN UP

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.
G
Gregory P. Smith committed
9a57179d74c1a20e3188779696c60c8dd812e6fb
Parent: 2925139
Committed by GitHub <noreply@github.com> on 4/28/2026, 8:06:23 AM