Comment 2 for bug 702914

Revision history for this message
Andrew Bennetts (spiv) wrote : Re: [Bug 702914] Re: AttributeError OOPS in codebrowse

Robert Collins wrote:
> Looks like a race condition on startup I think - is lazy_import
> threadsafe?

I doubt it. Certainly I don't think any effort has gone into trying to
make it threadsafe, so it's safest to assume not.

(Then again, I don't think you can say that import in general is
thread-safe either, it depends on what code is run at import time.
Python guarantees that the import machinery is threadsafe[1]… but
obviously it can't make guarantees about code run within that machinery,
and people do all sorts of strange things at import time.)

-Andrew.

[1] with two caveats: 1. imports shouldn't spawn threads and then wait
    on them, 2. imports must be completed before interpreter shutdown
    starts.
    <http://docs.python.org/library/threading.html#importing-in-threaded-code>