Global interpreter lock (GIL) is a mechanism used in computer language interpreters to synchronize the execution of

threads so that only one native thread can execute at a time. An interpreter that uses GIL always allows exactly one

thread to execute at a time, even if run on a multi-core processor.

Benefits and drawbacks

increased speed of single-threaded programs (no necessity to acquire or release locks on all data structures separately)

2. easy integration of C libraries that usually are not thread-safe

3. ease of implementation (having a single GIL is much simpler to implement than a lock-free interpreter or one using fine-grained locks).

Use of a global interpreter lock in a language effectively limits the amount of parallelism reachable through concurrency of a

single interpreter process with multiple threads. If the process is almost purely made up of interpreted code and does not

make calls outside of the interpreter for long periods of time (which can release the lock on the GIL on that thread while it

processes), there is likely to be very little increase in speed when running the process on a multiprocessor machine. Due to

signaling with a CPU-bound thread, it can cause a significant slowdown, even on single processors.

为什么要在tornado前面放nginx

原因在于,Tornado采用的的单进程单线程异步IO的网络模型。Python虽然有多线程,但是Python的解释器有GIL这点非常影响了Python

利用多核的能力,所以只能通过多进程来利用多核。既然多进程,一般就需要在前端放置nginx做为负载均衡的反向代理,或是使用这些应

用服务器的wsgi模块来管理进程的生命周期 。

对于含有IO阻塞的环境,比如网络通讯、磁盘读写, 当发生阻塞时,CPU是闲置的,此时如果就一个线程就没法处理其他事情了。

所以多线程可以提高CPU利用率。

 
 

参考:线程安全及Python中的GIL

 
 

理解Global interpreter lock的更多相关文章

  1. python之GIL(Global Interpreter Lock)

    一 介绍 ''' 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple nati ...

  2. **解释器全局锁(Global Interpreter Lock)

    解释器全局锁(Global Interpreter Lock),即Python为了保证线程安全而采取的独立线程运行的限制,说白了就是一个核只能在同一时间运行一个线程. [解决办法就是多进程和协程(协程 ...

  3. Python GIL(Global Interpreter Lock)

    一,介绍 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native t ...

  4. Python3 GIL(Global Interpreter Lock)与多线程

    GIL(Global Interpreter Lock)与多线程 GIL介绍 GIL与Lock GIL与多线程 多线程性能测试 在Cpython解释器中,同一个进程下开启的多线程,同一时刻只能有一个线 ...

  5. python之GIL官方文档 global interpreter lock 全局解释器锁

    0.目录 2. 术语 global interpreter lock 全局解释器锁3. C-API 还有更多没有仔细看4. 定期切换线程5. wiki.python6. python.doc FAQ ...

  6. Python GIL(Global Interpreter Lock)

    一.介绍 In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native threa ...

  7. python GIL(Global Interpreter Lock)

    一 介绍 ''' 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple nati ...

  8. 基于Cpython的 GIL(Global Interpreter Lock)

    一 介绍 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native t ...

  9. Python解释器是单线程应用 IO 密集型 计算密集型 GIL global interpreter lock

    [Python解释器是单线程应用] [任意时刻,仅执行一个线程] 尽管Python解释器中可以运行多个线程,但是在任意给定的时刻只有一个线程会被解释器执行. [GIL锁 保证同时只有一个线程运行] 对 ...

随机推荐

  1. lua工具库penlight--04路径和目录

    使用路径 程序不应该依赖于奇葩的系统,这样你的代码会难以阅读和移植.最糟糕的是硬编码的路径, windows和Unix的路径分隔符正好相反.最好使用path.join,它可以帮助你解决这个问题. pl ...

  2. 深度剖析java编码,彻底解决java乱码问题_1

    理解: 1,Java编译器(即编译成class文件时) 用的是unicode字符集. 2,乱码主要是由于不同的字符集相互转换导致的,理论上各个字符的编码规则是不同的,是不能相互转换的,所以根本解决乱码 ...

  3. IOS 中微信 网页授权报 key[也就是code]失效 解决办法

    枪魂微信平台ios手机点击返回 网页授权失败,报key失效.已经解决,原因是授权key只能使用一次,再次使用就会失效. 解决办法:第一次从菜单中进行授权时,用session记录key和open_id. ...

  4. 如何修改织梦官方flash幻灯片的方法

    源代码: <!-- size: 280px * 192px --> <script language='javascript'> linkarr = new Array(); ...

  5. SQL UNIQUE Constraint

    SQL UNIQUE Constraint The UNIQUE constraint uniquely identifies each record in a database table. The ...

  6. 哪些工具可以在word中快速绘制图形

    在数学试卷.论文.电子教案等编写过程中,我们经常要作出数学图形或图像,若用Word自身携带的绘图工具绘制,多有不便.比如一些曲线的形状很难画得像,画到位,作图时修修改改,颇为费力,所以需要借助一些辅助 ...

  7. iOS 功能代码 上传到 远程 码云私有库

    推送代码到远程私有库 创建私有库(注意:仓库名称LYDKit必须和本地仓库对应的名称一样) 复制远程仓库的地址,打开终端,cd到对应的本地库路径下面 >>> cd /Users/cx ...

  8. oracle11g安装完成后修改字符集

    author : headsen chen date:2018-05-10  10:27:16 oracle11g完成安装后,由于默认安装的时候无法指定字符集,所以手动修改字符集和10g版本一样的字符 ...

  9. Android 全局异常处理(三)

    用过安卓手机的用户以及安卓开发者们会时长碰到程序异常退出的情况,普通用户遇到这种情况,肯定非常恼火,甚至会骂一生垃圾软件,然后卸载掉.那么开发者们在开发过程中遇到这种情况给怎么办呢,当然,你不可能世界 ...

  10. maven web框架搭建

    前面我们描述了如何使用maven搭建一个最基本的Java Project 框架.在实际生产应用中,一般不会仅仅建立一个最基本的Java Project项目,目前 Java Web 开发已经成为Java ...