Re: Imports with hooks not thread safe?
"Gordon McMillan" <[email protected]>
| Newsgroups | gmane.comp.python.import |
|---|---|
| Message-ID | <3D2FF016.2985.99BDA4A@localhost> |
Anthony, I've created a bug report on SF: https://sourceforge.net/tracker/index.php?func=detail&aid=580952&group_id=5470&atid=105470 and assigned it to Tim for initial review. I'm suggesting that the imp module should grow acquire_lock and release_lock so hooks can do this right. -- Gordon http://www.mcmillan-inc.com/ On 12 Jul 2002 at 15:00, Anthony Tuininga wrote: > 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 > > > > _______________________________________________ > Import-sig mailing list > [email protected] > http://mail.python.org/mailman/listinfo/import-sig