[New-bugs-announce] [issue38095] Multi-threaded circular import fails with _DeadlockError when using importlib

Ronan Lamy report at bugs.python.org
Tue Sep 10 15:10:54 EDT 2019


New submission from Ronan Lamy <ronan.lamy at gmail.com>:

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')""",
 }

----------
components: Library (Lib)
messages: 351738
nosy: Ronan.Lamy
priority: normal
severity: normal
status: open
title: Multi-threaded circular import fails with _DeadlockError when using importlib
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38095>
_______________________________________


More information about the New-bugs-announce mailing list