Python解释器是单线程应用 IO 密集型 计算密集型 GIL global interpreter lock
【Python解释器是单线程应用】
【任意时刻,仅执行一个线程】
尽管Python解释器中可以运行多个线程,但是在任意给定的时刻只有一个线程会被解释器执行。
【GIL锁 保证同时只有一个线程运行】
对Python虚拟机的访问是由全局解释器锁(GIL)控制的。这个锁就是用来保证同时只有一个线程运行的。
【Python虚拟机】
Python代码的执行是由Python虚拟机(又名解释器主循环)进行控制的。在主循环中同时只能有一个控制线程在执行。
在内存中可以有许多程序,但是在任意给定时刻只能有一个程序在运行。
在多线程环境中,Python虚拟机将按照下面所述方式执行:
1、设置GIL;
2、切换一个线程去运行;
3、执行下面操作之一:
a.指定数量的字节码指令;
b.线程主动让出控制权;
4、把线程设置回睡眠状态(切换出线程)。
5、解锁GIL;
6、重复上述步骤

https://wiki.python.org/moin/GlobalInterpreterLock
In CPython, the global interpreter lock, or GIL, is a mutex that protects access to Python objects, preventing multiple threads from executing Python bytecodes at once. This lock is necessary mainly because CPython's memory management is not thread-safe. (However, since the GIL exists, other features have grown to depend on the guarantees that it enforces.)
CPython extensions must be GIL-aware in order to avoid defeating threads. For an explanation, see Global interpreter lock.
【阻碍多核】
The GIL is controversial because it prevents multithreaded CPython programs from taking full advantage of multiprocessor systems in certain situations. Note that potentially blocking or long-running operations, such as I/O, image processing, and NumPy number crunching, happen outside the GIL. Therefore it is only in multithreaded programs that spend a lot of time inside the GIL, interpreting CPython bytecode, that the GIL becomes a bottleneck.
However the GIL can degrade performance even when it is not a bottleneck. Summarizing those slides: The system call overhead is significant, especially on multicore hardware. Two threads calling a function may take twice as much time as a single thread calling the function twice. The GIL can cause I/O-bound threads to be scheduled ahead of CPU-bound threads. And it prevents signals from being delivered.
Python解释器是单线程应用 IO 密集型 计算密集型 GIL global interpreter lock的更多相关文章
- python之GIL(Global Interpreter Lock)
一 介绍 ''' 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple nati ...
- python GIL(Global Interpreter Lock)
一 介绍 ''' 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple nati ...
- python之GIL官方文档 global interpreter lock 全局解释器锁
0.目录 2. 术语 global interpreter lock 全局解释器锁3. C-API 还有更多没有仔细看4. 定期切换线程5. wiki.python6. python.doc FAQ ...
- Python GIL(Global Interpreter Lock)
一,介绍 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native t ...
- Python GIL(Global Interpreter Lock)
一.介绍 In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native threa ...
- **解释器全局锁(Global Interpreter Lock)
解释器全局锁(Global Interpreter Lock),即Python为了保证线程安全而采取的独立线程运行的限制,说白了就是一个核只能在同一时间运行一个线程. [解决办法就是多进程和协程(协程 ...
- IO密集型 计算密集型
参考:https://www.cnblogs.com/zhangyux/p/6195860.html 参考:廖雪峰 协程 gevent IO密集型任务指的是磁盘IO或者网络IO占主要的任务,计算量很小 ...
- IO密集型和计算密集型
我们常说的多任务或者单任务分为两种: IO密集型的任务 计算密集型的任务 IO密集型的任务或:有阻塞的状态,就是不一直会运行CPU(中间就一个等待状态,就告诉CPU 等待状态,这个就叫IO密集型 ...
- 浅谈Java两种并发类型——计算密集型与IO密集型
转载:https://blog.csdn.net/u013070853/article/details/49304099 核心是可以分别独立运行程序指令的计算单元.线程是操作系统能够进行运算调度的最小 ...
随机推荐
- PHP实现RabbitMQ的Publish/Subscribe
<?php /** * Created by PhpStorm. * User: 豆腐居士 * Date: 2018/5/30 * Time: 上午11:01 */ class AqiTask ...
- Using Single Alert For Messages And Confirmation Messages In Oracle Forms With Set_Alert_Button_Property
Learn how to use single Oracle Form's Alert object for warning/information messages and confirmation ...
- 【AOP】Spring AOP基础 + 实践 完整记录
Spring AOP的基础概念 ============================================================= AOP(Aspect-Oriented Pr ...
- 剑指Offer面试题51(Java版):数组中反复的数字
题目:在一个长度为n的数组里的全部数字都在0到n-1的范围内. 数组中某些数字是反复的,但不知道有几个数字反复了.也不知道每一个数字反复的次数.请找出数组中随意一个反复的数字. 比如假设输入长度为7的 ...
- Unity3D开发基础组件提取总结
在游戏开发过程中,除了逻辑功能的开发之外,还有非常多基础的模块.这些模块,对大部分手机网络游戏来说都是一样的.所以,在上个游戏已经上线运营大半年之际,我认为有必要将这些模块整理出来.让后面其它游戏的开 ...
- 性能测试脚本开发(LR.NET控件)
性能测试过程中,最耗费经历的就是编写性能测试脚本的过程,在大部分的测试工具中都是采用录制的方式,通过录制产生脚本,然后根据需要进行修改,以及参数化.有些时候为了能够完成某一个功能的脚本,需要将录制下来 ...
- 有问必答项目 -数据库设计文档(ask-utf-8)
有问必答项目 -数据库设计文档(ask-utf-8) 表前缀的使用 早期租用公共的服务器 一个数据库,保存多个项目(问答.电子商务.医院),为了区分这些项目,使用前缀分割 ask_ ec_ hospi ...
- ETL拉链算法汇总大全
拉链算法总结大全: 一.0610算法(追加) 1.删除仓库表的载入日期是本次载入日期的数据,以支持重跑 delete from xxx where start_dt >=$tx_date; 2. ...
- Spring Security实现短信验证码登录
Spring Security默认的一个实现是使用用户名密码登录,当初我们在开始做项目时,也是先使用这种登录方式,并没有多考虑其他的登录方式.而后面需求越来越多,我们需要支持短信验证码登录了,这时候再 ...
- ubuntu16.04--在标题栏显示网速
有时感觉网络失去响应,就通过Ubuntu 14.04自带的系统监视器程序来查看当前网速,但是这样很不方便,遂打算让网速显示在标题栏,那样就随时可直观的看到.一番搜索尝试后,成功实现!同时也实现了CPU ...