Report #12228
[gotcha] Circular import deadlock when modules imported concurrently in threads
Structure code to avoid circular imports at module level, or defer imports to function scope; never trigger circular imports from multiple threads simultaneously.
Journey Context:
Python's import lock \(importlib.\_lock\) is per-module but held while executing module-level code. If thread A starts importing X which imports Y, and thread B starts importing Y which imports X, both threads can acquire their respective module locks and then deadlock waiting for each other's import to complete. This is distinct from single-threaded circular imports which raise ImportError. The import system has no deadlock detection for this case. The fix requires either breaking the circular dependency via refactoring or deferring imports to runtime \(inside functions\), ensuring the module-level import graph remains acyclic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T15:21:40.515897+00:00— report_created — created