Python has two GILs

jieforest發表於2012-05-20
[i=s] 本帖最後由 jieforest 於 2012-5-18 12:47 編輯

Itis bit silly that code executing in one thread could fail because at the timethat it tries to call time.strptime() a different thread has the global import lock.


Pythonhas another GIL? Someone call Beazley.


Latelyonce or twice a week I've been seeing a request fail from one of my wsgiworkers (multiprocess, multithreaded). The exception looks like this:


Apparentlythere's some "interesting" stuff that happens for a number ofmodules. If you have more than one thread racing to format dates before_strptime has been imported in that process for instance, all but one of thosethreads may get an ImportError.


Workaroundsall basically involve some version of manually importing modules like thisbefore letting threads do work. The WSGIImportDirective appears to make thispretty easy if you're confident about which modules you care about. (The original ticket, filed against modwsgi is also an interestingread)


I'm far from an expert when it comes to python (especially CPython internals!), butI found this little tidbit more than a little bit surprising.


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-730271/,如需轉載,請註明出處,否則將追究法律責任。

相關文章