当前位置:网站首页>Problems caused by Gil problems and Solutions

Problems caused by Gil problems and Solutions

2022-06-25 08:27:00 victorwjw

python Because of its global interpreter lock GIL We can't achieve real parallel computing through threads . Need to be solved  IO intensive and   Computationally intensive   The parallel operation problem of .

IO intensive : Read the file , Read network Socket frequent . 

Computationally intensive : A lot of consumption CPU Mathematical and logical operations of , That is what we call parallel computation here .

IO intensive : The solution is synergy , frequently-used greenlet 、gevent、ayncio Wait to deal with

Simple understanding See connection below :

10 Minute quick understanding python asynchronous asyncio_ Xiaosheng listens to Yuyuan's blog -CSDN Blog _asyncio python

See you further   Link below


 

Computationally intensive : Commonly used concurrent.futures Module to handle

concurrent.futures modular , You can use multiprocessing To achieve true parallel computing .

The core principle is :concurrent.futures In the form of subprocesses , Run multiple... In parallel python Interpreter , So that python Programs can take advantage of multicore CPU To speed up execution . Because subprocesses are separated from the main interpreter , So their global interpreter locks are also independent of each other . Each subprocess can use a complete CPU kernel .

python concurrent.futures_weixin_30394981 The blog of -CSDN Blog

Python in concurrent.futures Module instruction _ Tuanzi Da Yuan Shuai's blog -CSDN Blog _concurrent.futures

原网站

版权声明
本文为[victorwjw]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250702186191.html