Skip to content

Commit 94842f0

Browse files
committed
Don't hold the runtime lock while we're importing modules in SerializationContext.
It can cause all kinds of deadlocks, since import operations execute arbitrary code, which can lock things and then attempt to compile. This can lead to deadlocks.
1 parent 321dcf4 commit 94842f0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

typed_python/SerializationContext.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,10 @@ def objectFromName(self, name, allowImport=True):
398398
if not allowImport:
399399
return None
400400

401-
return importlib.import_module(name[9:])
401+
# make sure to import outside of the lock
402+
# otherwise we can deadlock since importing
403+
# may trigger compilation
404+
return importlib.import_module(name[9:])
402405
except ModuleNotFoundError:
403406
_badModuleCache.add(name[9:])
404407
return None
@@ -425,7 +428,10 @@ def objectFromName(self, name, allowImport=True):
425428
if not allowImport:
426429
return None
427430

428-
module = importlib.import_module(moduleName)
431+
# make sure to import outside of the lock
432+
# otherwise we can deadlock since importing
433+
# may trigger compilation
434+
module = importlib.import_module(moduleName)
429435

430436
return getattr(module, objName, None)
431437
except ModuleNotFoundError:

0 commit comments

Comments
 (0)