[PEAK] Virtual Pythons

Phillip J. Eby pje at telecommunity.com
Wed Jul 28 01:56:31 EDT 2004

At 01:48 AM 7/28/04 -0400, Bob Ippolito wrote:
>On Jul 28, 2004, at 12:32 AM, Phillip J. Eby wrote:
>>One of the mildly annoying things about trying to develop any sort of 
>>really sophisticated extensible system in Python is that modules are 
>>global.  That is, you can only have one instance of a given module or package.
>>I do see a few complications:
>>  * There will probably need to be some sort of re-entrant locking to 
>> prevent multiple threads from trying to perform an import in the same 
>> module space at the same time, and it will need to be in addition to the 
>> pre-existing __import__ lock.
>Doesn't Python already have that?

Hence the phrase, "in addition to the pre-existing __import__ lock".  :)

Look at it this way: the existing import lock is *inside* the '__import__' 
function.  However, the module space mechanism wraps the existing 
'__import__' function, so when it checks its local version of the 'sys' 
module, there's no protection against a race condition there.  Thus, each 
module space needs its own re-entrant lock to protect its unique 
'sys.modules' against race conditions.

More information about the PEAK mailing list