You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gh-83065: Fix import deadlock by implementing hierarchical module locking
Fix a deadlock in the import system that occurs when concurrent threads
import modules at different levels of the same package hierarchy while
`__init__.py` files have circular imports.
The deadlock scenario (correctly analyzed by @emmatyping):
- Thread 1 imports `package.subpackage`, which imports `package.subpackage.module`
in its `__init__.py`
- Thread 2 imports `package.subpackage.module`, which needs to ensure
`package.subpackage` is loaded first
- Each thread holds a lock the other needs, causing deadlock
The fix introduces _HierarchicalLockManager that acquires all necessary
module locks in a consistent order (parent before child) for nested modules.
This ensures all threads acquire locks in the same order, preventing
circular wait conditions.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
0 commit comments