1、threading In fact, it can not achieve actual multithreading concurrency , At some point ta Only one thread can execute , However, due to the fast switching between threads , It will be assumed that multiple threads execute at the same time .
2、mutiprocessing It's multi process ,ta Concurrent operation can be achieved .
3、ThreadPoolExector Thread pool ,ta What's special is that you can create a specified number of thread pools , Maximize the rational use of resources , And and threading Better defensive than It is not easy to cause program crash .
We all know that using threads and processes can improve the execution efficiency of programs , However, it should be noted that not all programs can be improved when using multithreading and multiprocessing , Next, through the data experiment , We can see that multithreading is going on cpu Intensive computing does not improve efficiency, but will be more time-consuming than ordinary single thread .
According to the experimental results, we come to the conclusion that cpu In intensive computing, we can use multiple processes to improve execution efficiency , stay io In intensive computing, we can choose multithreading to improve execution efficiency .
The figure shows the comparison of common methods of multithreading and multiprocessing , Please like the collection comments …
If you have a deeper understanding of the relevant content, take a look at the video explanation of this blogger ~【【2021 The latest version 】Python Concurrent programming practice , With multithreading 、 Multi process 、 Multi process acceleration program running - Bili, Bili 】 https://b23.tv/6wF7v3s