cool hit counter Python multiprocessing_Intefrankly

Python multiprocessing


The concept of multiprocessing is very common in operating systems to enable multitasking, i.e. from single instance execution of tasks to multiple execution of tasks. The master is responsible for assigning tasks and the worker is responsible for executing them, which is actually the same as the resource scheduling of many distributed systems.

In practice there is a scenario where there are many sources of data and then they need to be processed at the same time, at this time if the data is processed one by one, then it is single task mode and the efficiency can be imagined.

It's like when we were kids doing homework, Maths, Politics, Geography, History, etc. If the homework was due tomorrow, we did it one by one at night, and at this time we imagined how nice it would be to be able to start all the homework at the same time and keep switching between different assignments. Therefore, I use python's multi-process to process data to achieve a multitasking state, the general idea can be seen in a summary diagram below:

(a) The introduction of multiprocessing puts multitasks inside a queue by creating a queue.

Creating the corresponding tasks, one as the processing of the data and one as the consumption of the data after processing, can be seen as a producer-consumer model .

The core implementation is shown below:

First, a queue q is created as a multi-process management and data sharing; Then, two child processes p,p1 are created, one as a producer and the other as a consumer after data processing. Then we define the processing logic for the producer and the consumer.

Finally, let's launch the program to see if the background is multitasking as we thought it would be.

As you can see by the process, there are already 3 python processes executing, which enables multi-process and inter-process communication.


Recommended>>
1、A little summer sharing a few practical PowerPoint making tips
2、Summary of deep learning image annotation tools
3、Another missed appointment Tesla still hasnt completed Autopilot 20 selfdriving demo
4、Smart city bridge sensors will usher in an industrial explosion
5、Summary of the most current fully automated driving road test licenses

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号