V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
jell
V2EX  ›  Python

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

  •  
  •   jell · 2015-07-12 16:50:39 +08:00 · 3106 次点击
    这是一个创建于 3208 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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)

    11 条回复    2015-07-14 14:13:22 +08:00
    denghongcai
        1
    denghongcai  
       2015-07-12 20:12:17 +08:00
    这机翻的么?怎么都读不通顺
    jackysc
        2
    jackysc  
       2015-07-12 20:40:57 +08:00
    老实说没看明白。。
    janxin
        3
    janxin  
       2015-07-12 22:31:43 +08:00
    看起来像个人的学习笔记
    saber000
        4
    saber000  
       2015-07-13 12:00:31 +08:00   ❤️ 1
    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
        5
    jell  
    OP
       2015-07-13 19:02:24 +08:00
    @janxin 对的 看博客时,简要翻译一下,记在v2ex增强记忆
    jell
        6
    jell  
    OP
       2015-07-13 19:06:46 +08:00
    @denghongcai 自己翻译的,比较粗糙。哈
    jell
        7
    jell  
    OP
       2015-07-13 19:07:43 +08:00
    @janxin 记在剪贴板上的,都忘记原文出处了,不然贴上链接
    jell
        8
    jell  
    OP
       2015-07-13 19:09:35 +08:00
    @saber000 你是哪边看到的,我记得是stackoverflow,方便贴上链接吗?
    janxin
        9
    janxin  
       2015-07-13 20:38:26 +08:00
    saber000
        10
    saber000  
       2015-07-14 14:12:43 +08:00
    saber000
        11
    saber000  
       2015-07-14 14:13:22 +08:00
    @jell 谷歌机翻嘿嘿嘿嘿嘿嘿
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3294 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 14:12 · PVG 22:12 · LAX 07:12 · JFK 10:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.