Imports with hooks not thread safe?
Anthony Tuininga <[email protected]>
| Newsgroups | gmane.comp.python.import |
|---|---|
| Message-ID | <[email protected]> |
I just joined this list so my apologies if this has been discussed before. The list (from the archives) seems close to dead with a suggestion to kill it permanently.... :-) I noticed that in PyImport_ImportModuleEx, that a lock is held until the import is completed or an exception is raised. The only problem is that the higher level interface PyImport_Import does __NOT__ hold the lock and this is the method that is used for hooks. The builtin function __import__ calls PyImport_ImportModuleEx but if that function is replaced with a call to a hook, no locking takes place which makes the import mechanism not thread safe. My question is: would there be a problem with holding the lock during PyImport_Import? If there is, would there be a problem with exposing a method that would do the import lock? The only thing that is currently available is imp.lock_held() but that simply states whether or not the import lock is held and nothing that I could see provides any mechanism for acquiring the import lock. I am using Installer (from Gordon McMillan) and it is using its own locking mechanism which seems to break inside PythonCOM (from Mark Hammond) if a large enough quantity of threads are executing. All of my imports are done within the import of the main module which is done using the normal method but I would like to solve this problem in a more permanent way as otherwise I will have to fork Installer for our own internal use. Blech. -- Anthony Tuininga [email protected] Computronix Distinctive Software. Real People. Suite 200, 10216 - 124 Street NW Edmonton, AB, Canada T5N 4A3 Phone: (780) 454-3700 Fax: (780) 454-3838 http://www.computronix.com