[Python-Dev] Dealing with import lock deadlock in Import Hooks (original) (raw)

Arnaud Fontaine arnaud.fontaine at nexedi.com
Mon Aug 12 09:39:36 CEST 2013


[I initially posted this email to python-list but didn't get any reply, probably because this is too related to python core, so I'm posting it again here, hope that's ok...]

Hello,

I'm currently working on implementing Import Hooks (PEP302) with Python 2.7 to be able to import modules whose code is in ZODB. However, I have stumbled upon a widely known issue about import deadlock[0][1] (note that this issue is not directly related to ZODB, but a more general question about dealing with import lock deadlock for Import Hooks), basically:

Thread 1 is trying to import a module 'foo.bar' (where 'foo' is a package containing dynamic modules) handled by Import Hooks I implemented, so import lock is acquired before even running the hooks (Python/import.c:PyImport_ImportModuleLevel()). Then, these import hooks try to load objects from ZODB and a request is sent and handled by another thread (Thread 2) which itself tries to import another module. Of course, this causes a deadlock because the first thread still holds import lock.

I have thought about the following solutions:

Any thoughts or suggestion welcome, thanks!

Regards, Arnaud Fontaine



More information about the Python-Dev mailing list