当前位置:网站首页>GIL问题带来的问题,解决方法
GIL问题带来的问题,解决方法
2022-06-25 07:02:00 【victorwjw】
python因为其全局解释器锁GIL而无法通过线程实现真正的平行计算。需要解决 IO密集型 和 计算密集型 的平行运算问题。
IO密集型:读取文件,读取网络套接字频繁。
计算密集型:大量消耗CPU的数学与逻辑运算,也就是我们这里说的平行计算。
IO密集型:解决的方法是协程, 常用的greenlet 、gevent、ayncio等来处理
简单理解 见下面连接:
10分钟快速理解python异步asyncio_小生听雨园的博客-CSDN博客_asyncio python
深入一点见 下面链接
计算密集型:常用concurrent.futures模块来处理
concurrent.futures模块,可以利用multiprocessing实现真正的平行计算。
核心原理是:concurrent.futures会以子进程的形式,平行的运行多个python解释器,从而令python程序可以利用多核CPU来提升执行速度。由于子进程与主解释器相分离,所以他们的全局解释器锁也是相互独立的。每个子进程都能够完整的使用一个CPU内核。
python concurrent.futures_weixin_30394981的博客-CSDN博客
Python 中 concurrent.futures 模块使用说明_团子大圆帅的博客-CSDN博客_concurrent.futures
边栏推荐
- Number theory template
- 双周投融报:资本埋伏Web3基础设施
- 软件确认测试有什么作用?确认测试报告的价格是多少?
- 唐老师讲运算放大器(第七讲)——运放的应用
- 什么是SKU和SPU,SKU,SPU的区别是什么
- leetcode. 13 --- Roman numeral to integer
- Electronics: Lesson 011 - experiment 10: transistor switches
- Is the securities account given by Qiantang education business school safe? Can I open an account?
- Wechat applet introduction record
- Daily question brushing record (III)
猜你喜欢

PH neutralization process modeling

A solution to slow startup of Anaconda navigator

Modeling and fault simulation of aircraft bleed system

TCP stuff

How to do factor analysis? Why should data be standardized?

家庭服务器门户Easy-Gate

STM32CubeMX 学习(5)输入捕获实验

Biweekly investment and financial report: capital ambush Web3 infrastructure

Electronics: Lesson 013 - Experiment 14: Wearable pulsed luminaries

Internet of things (intelligent irrigation system - Android end)
随机推荐
Websocket understanding and application scenarios
FFT [template]
自制坡道,可是真的很香
Scanpy (VII) spatial data analysis based on scanorama integrated scrna seq
Find out the possible memory leaks caused by the handler and the solutions
Use Adobe Acrobat pro to resize PDF pages
Bat start NET Core
How to calculate the fuzzy comprehensive evaluation index? How to calculate the four fuzzy operators?
Deep learning series 48:deepfaker
Mr. Tang's lecture on operational amplifier (Lecture 7) -- Application of operational amplifier
Niuke: flight route (layered map + shortest path)
The era of enterprise full cloud -- the future of cloud database
打新债的安全性 有风险吗
Bluecmsv1.6- code audit
2022年毕业生求职找工作青睐哪个行业?
Log in to MySQL 5.7 under ubuntu18 and set the root password
家庭服务器门户Easy-Gate
A solution to slow startup of Anaconda navigator
Nodehandle common member functions
TCP MIN_ A dialectical study of RTO