You see my code above, because I ran on the 40 core machine, so I started 40 processes, but look at the CPU case.

MingmingA lot of tasks，But there is no full, a lot of nuclear empty,

Like these times, it doesn’t move at all.

logThe display does start 40 processes, but those processes don’t move as if they started.

The running log is as follows:

I tried again to start the 10 process, and finally the program runs almost as long as 40!!!

What’s the matter? Ask the great God to point out. (the for cycle is very long and the calculation is strong enough)

Answer 0:

multiprocessing.Pool It is just used to start multiple processes instead of starting a process on each core. In other words, the Python interpreter itself does not do load balancing at every core or processor. This is determined by the operating system. If your job is particularly computationally intensive,The operating system does allocate more core, but this is not what Python or code can control or specify.

multiprocessing.Pool(num)The num can be very small or very large, for example, I/O intensive operation, this value can be greater than the number of CPU.

Hardware resource allocation is determined by the operating system, and if you want every core to work, you need to start more from the operating system ~

Answer 1:

The intensity of the calculation is not enough, and the preceding processes are finished.

Answer 2:

I think the explanation here is clearer. Https://stackoverflow.com/que…