pythongil是什么
pythongil是什么
1、说明
是全局解释器锁,每个线程在执行时候都需要先获取GIL,保证同一时刻只有一个线程可以执行代码,即同一时刻只有一个线程使用CPU,也就是说多线程并不是真正意义上的同时执行。
2、产生原因
(1)GuidovanRossum(吉多·范罗苏姆)创建python时就只考虑到单核cpu。
(2)解决多线程之间数据完整性和状态同步的最简单方法自然就是加锁。于是有了GIL这把超级大锁。
(3)cpython解析只允许拥有GIL全局解析器锁才能运行程序。
(4)保证同一个时刻只允许一个线程可以使用cpu。
(5)以前写cpython解析器的时候就考虑一个cpu情况。
(6)由于大量的程序开发者接收了这套机制,现在代码量越来越多,已经不容易通过c代码去解决这个问题。
3、gil锁的释放时机
(1)遇到像i/o操作这种会有时间空闲情况造成cpu闲置的情况会释放Gil
(2)会有一个专门ticks进行计数一旦ticks数值达到100这个时候释放Gil锁线程之间开始竞争Gil锁(说明:
(3)ticks这个数值可以进行设置来延长或者缩减获得Gil锁的线程使用cpu的时间)
以上就是pythongil的介绍,大家在了解基本的用法后,可以去找一些gil的实例进行练习。更多Python学习教程请关注IT培训机构:千锋教育。

相关推荐HOT
更多>>
python中s3cmd是什么?
python中s3cmd是什么?本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。简单介绍:可以实现使用s3对象存储安装方式:yuminstalls3cmd...详情>>
2023-11-14 19:15:02
python中如何使用pandas实现行数据添加
python中如何使用pandas实现行数据添加python中,pandas是一个数据分析包,可以对数据进行很方便的处理提供了高效地操作大型数据集所需的工具。...详情>>
2023-11-14 16:35:59
python迭代器中Yield方法怎么用?
python迭代器中Yield方法怎么用?Yield用于返回数据,程序执行到yield后,返回结果,记住当前状态,暂停执行,下次调用时,根据上次的状态,返回...详情>>
2023-11-14 16:11:13
python元组拆包如何实现?
python元组拆包如何实现?1、说明把元组一一对应拆出来,就叫做元组拆包。拆包有个要求,元组中的元素数量必须跟接受这些元素的空挡数一致,否则...详情>>
2023-11-14 13:24:22热门推荐
python中any函数如何使用?
沸python operator模块有何用法?
热python中s3cmd是什么?
热python中getattribute方法作用是什么?
新python如何使用TemporaryFile()方法创建临时文件?
python中sys模块是什么?
python的ndarray与pandas的series如何相互转换?
python中如何使用pandas实现行数据添加
python迭代器中Yield方法怎么用?
python中temp是什么意思?
python中Cartopy是什么
python入门:方差和标准差的区别
python切片如何作为占位符使用
python元组拆包如何实现?
技术干货






