The difference between Python multi-process apply and Apply_async

Source: Internet
Author: User
Why is that?

Because the process of switching is the operating system to control, preemptive switching mode.
We first run the main process, the CPU is running fast ah, this short line of code, there is no opportunity to switch the operating system process, the main process is finished, the entire program is finished. The child process completely has no chance to switch to the program and it is over.

Apply is a blocking type.

First the main process starts running, touches the child process, the operating system switches to the child process, waits for the child process to finish running, switches to another child process until all the child processes have finished running. Then switch to the main process and run the rest of the section.

The Apply_async is asynchronous and non-blocking.

First the main process begins to run, after the child process, the main process said: Let me run first enough, wait until the operating system to switch the process, the child process to run. Think our program is too short, but not wait for the operating system to switch processes, the main process is finished running.

If you want the child process to execute, tell the main process: You wait until all the child processes have finished executing, and then run the remainder.

Note: Close must be called before the join.

A little D wound.
Links: https://www.jianshu.com/p/0a55507f9d9e
Source: Pinterest
The copyright of the book is owned by the author, and any form of reprint should be contacted by the author for authorization and attribution.

The difference between Python multi-process apply and Apply_async

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.