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/，如需转载，请注明出处，否则将追究法律责任。