Skip to content

Commit 29a4f34

Browse files
committed
Fix a bug in SerializationContext that could cause deadlocks
1 parent 5676bc7 commit 29a4f34

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

typed_python/SerializationContext.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,12 @@ def objectFromName(self, name, allowImport=True):
336336
if moduleName in _badModuleCache or not allowImport:
337337
return None
338338

339-
module = importlib.import_module(moduleName)
339+
module = None
340+
341+
# make sure not to import the module under lock
342+
if module is None:
343+
module = importlib.import_module(moduleName)
344+
340345
except ModuleNotFoundError:
341346
_badModuleCache.add(moduleName)
342347
return None
@@ -402,10 +407,12 @@ def objectFromName(self, name, allowImport=True):
402407
if not allowImport:
403408
return None
404409

405-
# make sure to import outside of the lock
406-
# otherwise we can deadlock since importing
407-
# may trigger compilation
408-
module = importlib.import_module(moduleName)
410+
module = None
411+
# make sure to import outside of the lock
412+
# otherwise we can deadlock since importing
413+
# may trigger compilation
414+
if module is None:
415+
module = importlib.import_module(moduleName)
409416

410417
return getattr(module, objName, None)
411418
except ModuleNotFoundError:

0 commit comments

Comments
 (0)