Multi-process Knowledge Addendum finishing

Source: Internet
Author: User

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

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.