Python GIL(Global Interpreter Lock)
2017-08-30 16:48
316 查看
阅读目录
一 介绍
二 GIL介绍
三 GIL与Lock
四 GIL与多线程
五 多线程性能测试
I/O密集型:多线程效率高
应用场景:
多线程用于IO密集型,如socket,爬虫,web
多进程用于计算密集型,如金融分析
一 介绍
二 GIL介绍
三 GIL与Lock
四 GIL与多线程
五 多线程性能测试
一 介绍
from multiprocessing import Process from threading import Thread import threading import os,time def work(): time.sleep(2) print('===>') if __name__ == '__main__': l=[] print(os.cpu_count()) #本机为4核 start=time.time() for i in range(400): # p=Process(target=work) #耗时12s多,大部分时间耗费在创建进程上 p=Thread(target=work) #耗时2s多 l.append(p) p.start() for p in l: p.join() stop=time.time() print('run time is %s' %(stop-start))
I/O密集型:多线程效率高
应用场景:
多线程用于IO密集型,如socket,爬虫,web
多进程用于计算密集型,如金融分析
相关文章推荐
- Python 中的 GIL(Global Interpreter Lock) 全局解释器锁是什么?
- python-GIL(Global Interpreter Lock)
- Python GIL(Global Interpreter Lock)
- Python GIL(Global Interpreter Lock,全局解释器锁)
- python GIL (Global Interpreter Lock)
- Python 中的 GIL(Global Interpreter Lock) 全局解释器锁是什么?
- Python GIL(Global Interpreter Lock)
- Python GIL(Global Interpreter Lock)
- python之GIL官方文档 global interpreter lock 全局解释器锁
- GIL全局锁(Global Interpreter Lock)
- GIL全局锁(Global Interpreter Lock)
- 基于Cpython的 GIL(Global Interpreter Lock)
- **解释器全局锁(Global Interpreter Lock)
- Python系列之 - 锁(GIL,Lock,Rlock,Event,信号量)
- Thread State and the Global Interpreter Lock
- Thread State and the Global Interpreter Lock
- python2.7以下出 NameError: global name 'FileNotFoundError' is not defined的解决方案
- Global Interpretor Lock
- python的GIL
- Python学习日记(一)------------Using the Python Interpreter