[Python-Dev] Dealing with import lock deadlock in Import Hooks (original) (raw)
Arnaud Fontaine arnaud.fontaine at nexedi.com
Tue Aug 13 10:28:42 CEST 2013
- Previous message: [Python-Dev] Dealing with import lock deadlock in Import Hooks
- Next message: [Python-Dev] Dealing with import lock deadlock in Import Hooks
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Antoine Pitrou <solipsis at pitrou.net> writes:
On Tue, 13 Aug 2013 11:06:51 +0900 Arnaud Fontaine <arnaud.fontaine at nexedi.com> wrote:
I suggested the same in my initial email, but I was wondering if there could be any issue by releasing the lock in findmodule()/loadmodule() until the module is actually added to sys.modules. Well, you are obviously on your own with such hacks. There is a reason the lock exists.
Yes. Actually, I was thinking about implementing something similar to what has been done in Python 3.3 but for Python 2.7 with a corser-grain lock. From my understanding of import.c, it should work but I was hoping that someone with more experience in import code would confirm:
Currently, I have a package, foo, registered into sys.meta_path which loads modules through its find_module() and load_module() methods (PEP302).
Access to load_module() of this package is protected by a RLock I defined, so that modules within foo cannot be imported in parallel. Until the module is added to sys.modules and then the code loaded, release the import lock.
For find_module(), only filter the full module name and if this is a module from foo package, then acquired the same RLock defined for load_module() to access variables shared with find_module().
Also, if a patch backporting the features from Python 3.3 to import.c for Python 2.7 would be written, is there any chance it could be accepted?
Regards,
Arnaud Fontaine
- Previous message: [Python-Dev] Dealing with import lock deadlock in Import Hooks
- Next message: [Python-Dev] Dealing with import lock deadlock in Import Hooks
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]