当前位置:网站首页>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
边栏推荐
- How to calculate the information entropy and utility value of entropy method?
- Can I grant database tables permission to delete column objects? Why?
- In 2022, which industry will graduates prefer when looking for jobs?
- Scanpy(七)基于scanorama整合scRNA-seq实现空间数据分析
- Drawing of clock dial
- Is there any risk in the security of new bonds
- Luogu p2048 [noi2010] super Piano (rmq+ priority queue)
- TCP MIN_ A dialectical study of RTO
- [Mobius inversion]
- Stm32cubemx learning (5) input capture experiment
猜你喜欢
A solution to slow startup of Anaconda navigator
唐老师讲运算放大器(第七讲)——运放的应用
First experience Amazon Neptune, a fully managed map database
Deep learning series 45: overview of image restoration
Electronics: Lesson 010 - Experiment 8: relay oscillator
Quickly build a real-time face mask detection system in five minutes (opencv+paddlehub with source code)
TCP and UDP
物联网毕设(智能灌溉系统 -- Android端)
Self made ramp, but it really smells good
C examples of using colordialog to change text color and fontdialog to change text font
随机推荐
Rosparam statement
TCP MIN_RTO 辩证考
How to do factor analysis? Why should data be standardized?
Cloud computing exam version 1 0
Basic record of getting started with PHP
Deep learning series 45: overview of image restoration
Common action types
iframe简单使用 、获取iframe 、获取iframe 元素值 、iframe获取父页面的信息
物联网毕设(智能灌溉系统 -- Android端)
Electronics: Lesson 008 - Experiment 6: very simple switches
Go language learning tutorial (13)
What problems do you worry about when you want to switch to software testing?
初体验完全托管型图数据库 Amazon Neptune
Modeling and fault simulation of aircraft bleed system
STM32CubeMX 學習(5)輸入捕獲實驗
How to calculate the correlation coefficient and correlation degree in grey correlation analysis?
STM32CubeMX 学习(5)输入捕获实验
[QT] qtcreator shortcut key and QML introduction
软件确认测试有什么作用?确认测试报告的价格是多少?
A solution to slow startup of Anaconda navigator