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