Report #14402
[gotcha] Circular imports involving threads cause deadlock due to import lock
Never trigger imports inside thread startup code \(Thread.\_\_init\_\_ or target function\) if the import chain could be active on the main thread; import all modules at top-level before spawning threads
Journey Context:
Python's import system uses a global lock \(import\_lock\) to prevent concurrent imports of the same module. If Thread A starts importing module X, which imports Y, and Thread B \(started by X's import side effects\) tries to import Z, which depends on X, a deadlock occurs. This is common in plugin systems or frameworks that auto-import on class definition. People place imports inside functions to avoid circular dependencies, but if that function runs in a new thread during an ongoing import, it hangs silently. The fix is to ensure the import graph is fully resolved before any thread creation, or use explicit import hooks rather than implicit import-time side effects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:23:53.756471+00:00— report_created — created