In construction ...
I. Multiprocessing. Pool related Addendum
1. Map:
When using a process pool, we generally use the Apply and Apply_async methods to apply for process execution tasks, but there are a number of other ways that map is used for elements in a sequence.
Use pool when making the same function call to implement concurrency. The method used is very similar to the built-in function map (), but it becomes a pool call with a thread, as shown in the following example:
1 ImportMultiprocessing2 3 deffunc1 (x):4 Print(x *x)5 6 if __name__=='__main__': 7Pool =multiprocessing. Pool (Multiprocessing.cpu_count ())8I_list = Range (8)9Pool.map (func1, I_list)
Operation Result:
We can see that the results are as expected, and that each element in the sequence is processed using the FUNC1 function, and we can also find that the results are printed one by one at run time, indicating that map is blocking execution, similar to the Apply method, so the map has a non-blocking version as opposed to it.
2. Map_async method
The Map_async method is the non-blocking version of the map method, and the usage is similar to the Apply_async, which needs to wait for the process to end after the close process pool, and also to accept the callback function, as follows:
3. IMAP and
2. Multiprocessing.cpu_count ()
3. Threading.currentthread ()
Two. Expansion: deco--modified concurrency
Multi-process Knowledge Addendum finishing