首页 > Python > 翻译How does multi-threading work with Ice for Python?

翻译How does multi-threading work with Ice for Python?

2012年3月20日 发表评论 阅读评论

Python supports multi-threaded programming, but the interpreter is inherently single threaded: a global interpreter lock (GIL) allows only one thread at a time to execute a Python opcode. Despite this limitation, careful management of the GIL can still provide performance improvements; for example, a thread that is about to block on I/O can release the GIL so a different thread can use the CPU in the meantime. Although the GIL is an implementation detail that is typically of interest only to developers of Python extensions, it is still important for Python programmers to understand the semantics of the GIL and how it affects their applications.

Python程序是支持多线程的,但是它的解释器本质上确是单线程的。因为GIL(全局解释器锁)在执行Python代码的时候一次只允许开启一个线程。虽然有这个限制,但是在GIL控制方面,还有可以提升性能的。比如,一个线程在I/O阻塞的时候释放GIL,让另一个线程去使用CPU。一般GIL的实现细节应该是Python扩展开发人员应该关心的。但是它对于我们理解GIL的原因和它对我们项目的影响同样重要。

除非注明,文章为IT热血青年原创,欢迎转载!转载请注明本文地址,谢谢。
本文地址:http://blog.itblood.com/how-does-multi-threading-work-with-ice-for-python.html

分类: Python 标签: , ,
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.