classification
Title: Multi-threaded circular import fails with _DeadlockError when using importlib
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Ronan.Lamy
Priority: normal Keywords:

Created on 2019-09-10 19:10 by Ronan.Lamy, last changed 2019-09-10 19:10 by Ronan.Lamy.

Messages (1)
msg351738 - (view) Author: Ronan Lamy (Ronan.Lamy) * Date: 2019-09-10 19:10
The IMPORT_NAME bytecode has a fast path calling PyImport_ImportModuleLevelObject() that behaves differently from importlib. In particular, test_circular_imports() in test_threaded_import.py fails due to a _DeadlockError if you replace some import statements with importlib.import_module() as in

diff --git a/Lib/test/test_importlib/test_threaded_import.py b/Lib/test/test_importlib/test_threaded_import.py
index d1f64c7..243d2c1 100644
--- a/Lib/test/test_importlib/test_threaded_import.py
+++ b/Lib/test/test_importlib/test_threaded_import.py
@@ -60,8 +60,12 @@ circular_imports_modules = {
         x = 'b'
         import D
         """,
-    'C': """import B""",
-    'D': """import A""",
+    'C': """if 1:
+        import importlib
+        B = importlib.import_module('B')""",
+    'D': """if 1:
+        import importlib
+        A = importlib.import_module('A')""",
 }
History
Date User Action Args
2019-09-10 19:10:54Ronan.Lamycreate