[Python-bugs-list] [ python-Bugs-580952 ] import lock should be exposed
SourceForge.net
noreply@sourceforge.net
Wed, 12 Feb 2003 13:54:04 -0800
Bugs item #580952, was opened at 2002-07-13 09:06
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=580952&group_id=5470
Category: Python Interpreter Core
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Gordon B. McMillan (gmcm)
Assigned to: Guido van Rossum (gvanrossum)
Summary: import lock should be exposed
Initial Comment:
See
http://mail.python.org/pipermail/import-sig/2002-July/000179.html
In brief, a good import hook needs to use an import
lock. But if it creates it's own import lock, you have the
possibility of a deadlock, since PyImport_ImportModuleEx
still uses the core lock. So one thread can end up
acquiring the hook's lock, then seeking the core lock.
While another holds the core lock, but does an import
(routed through the hook) and seeks the hook's lock.
Seems to me exposing the core lock through
imp.acquire_lock() and imp.release_lock() would
allow a properly coded hook to avoid this.
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2003-02-12 16:54
Message:
Logged In: YES
user_id=6380
OK, this is fixed in CVS for Python 2.3. See #683257 for a
question about backporting.
----------------------------------------------------------------------
Comment By: Jason Hildebrand (jdhildeb)
Date: 2003-02-08 23:32
Message:
Logged In: YES
user_id=173690
I've attached the patches against both 2.3-2.2.99 and 2.2.2;
they are available in patch # 683257.
----------------------------------------------------------------------
Comment By: Jason Hildebrand (jdhildeb)
Date: 2003-02-08 23:05
Message:
Logged In: YES
user_id=173690
For what it's worth, Webware for Python users are exposed to
this bug, too, as Webware is multithreaded and uses an
import hook. This has caused me some amount of grief, and
I've been happy to figure out the cause (the import
collisions were causing really weird things to happen).
I've attached a patch to import.c which exposes the
acquire_lock() and release_lock() functions. Since
modifying Webware's import routine to use this these
functions, I have been completely unable to reproduce the
buggy behaviour (which had previously been easy to reproduce).
It would be great to have this merged in for Python 2.3, as
projects using both custom import hooks and threads have no
other reliable way of solving this problem.
----------------------------------------------------------------------
Comment By: Gordon B. McMillan (gmcm)
Date: 2002-07-14 17:34
Message:
Logged In: YES
user_id=4923
Yes, I would just like to expose the current lock_import and
unlock_import to C and Python.
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2002-07-14 17:06
Message:
Logged In: YES
user_id=31435
I don't understand how imports work, at least not at this
level. I note that the current lock_import() and
unlock_import() arrange to implement a reentrant lock: in
the absence of you supplying a patch, are these the
functions you would like to see exposed? Given the games
being played here, it seems too dangerous to expose the
*underlying* lock's acquire and release methods directly.
Assigned to Guido for cogitation.
----------------------------------------------------------------------
Comment By: Gordon B. McMillan (gmcm)
Date: 2002-07-13 09:10
Message:
Logged In: YES
user_id=4923
Assigning to Tim for initial review.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=580952&group_id=5470