关于 python GIL 一些内部运行机理

2015-07-12 16:50:39 +08:00
 jell

1) 当你阻塞于os,如果你的代码在大量等待系统,GIL不会干扰你因为此时你没有编译python
字节码
2) 当你在简单执行内部指令时,比如操作大量字符串或者位运算。GIL不会产生干扰因为这些都
是作用于 字节码
3) 当你在执行C扩展模块。 Numpy,python图像库等。
4) 如果你真的依赖某段python代码。Cython也可以通过 with-statement 释放GIL
5) 如果不是C扩于展限制。Jython和Ironthon没有GIL
6) PyPy 也提高了之前受限于GIL的劣势。(但PyPy有自己的GIL)

3114 次点击
所在节点    Python
11 条回复
denghongcai
2015-07-12 20:12:17 +08:00
这机翻的么?怎么都读不通顺
jackysc
2015-07-12 20:40:57 +08:00
老实说没看明白。。
janxin
2015-07-12 22:31:43 +08:00
看起来像个人的学习笔记
saber000
2015-07-13 12:00:31 +08:00
1) When you blocked in os, if your code is a lot of waiting for the system, GIL will not disturb you because at this time you do not have to compile python bytecode
2) When you instructions simple internal execution, such as operating a large number of string or bit computing. GIL interference will not occur because these are acting on the bytecode
3) When you execute a C extension module. Numpy, python image libraries.
4) If you really depend on certain python code. Cython may also release GIL through with-statement
5) If it is not expanded to show C limit. Jython and Ironthon no GIL
6) PyPy also improved the previous limited by GIL disadvantage. (But PyPy has its own GIL)
jell
2015-07-13 19:02:24 +08:00
@janxin 对的 看博客时,简要翻译一下,记在v2ex增强记忆
jell
2015-07-13 19:06:46 +08:00
@denghongcai 自己翻译的,比较粗糙。哈
jell
2015-07-13 19:07:43 +08:00
@janxin 记在剪贴板上的,都忘记原文出处了,不然贴上链接
jell
2015-07-13 19:09:35 +08:00
@saber000 你是哪边看到的,我记得是stackoverflow,方便贴上链接吗?
janxin
2015-07-13 20:38:26 +08:00
saber000
2015-07-14 14:12:43 +08:00
saber000
2015-07-14 14:13:22 +08:00
@jell 谷歌机翻嘿嘿嘿嘿嘿嘿

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/205144

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX