ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Python has two GILs

Python has two GILs

原创 Linux操作系统 作者:jieforest 时间:2012-05-20 11:24:26 0 删除 编辑
[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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-04-23

  • 博文量
    442
  • 访问量
    521905