Thread-safe atomic operation

Aahz Maruch aahz at netcom.com
Tue Apr 11 16:16:27 EDT 2000


In article <1256659126-41087547 at hypernet.com>,
Gordon McMillan <gmcm at hypernet.com> wrote:
>Dong-gweon Oh writes:
>>
>> Are these statements thread-safe?
>> 1. import xxx
>> 2. xxx = __import__('xxx')
>> 3. reload(xxx)
>> 4. dict['xxx'] = sys.modules['xxx']
>> 5. dict.has_key('xxx')
>
>Numbers 2 and 4 could be interrupted between evaluation of 
>the RHS and assigment to LHS. For #2 that would be of 
>concern only if xxx was a global.

Are you absolutely certain about item 1?  That implies that Python as a
whole could block on importing a module that did something like

for i in range(100):
  sleep(1)
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Why doesn't "Just Say NO" include caffeine, nicotine, alcohol, Prozac,
and Ritalin?  --Aahz



More information about the Python-list mailing list