Use of the starmap of the Python process pools pool

Source: Internet
Author: User

#!/usr/bin/env python3from functools Import partialfrom itertools import repeatfrom multiprocessing import Pool, freeze_s  Upportdef func (A, B):    return a + bdef main ():    A_args = []    second_arg = 1 with    pool () as pool:        L = Pool.starmap (func, [(1, 1), (2, 1), (3, 1)])        M = Pool.starmap (func, Zip (A_args, repeat (second_arg)))        N = Pool.map (Partial (func, B=second_arg), A_args)        Assert L = = M = Nif __name__== "__main__":    freeze_support ()    main ()

The original view here: Https://stackoverflow.com/questions/5442910/python-multiprocessing-pool-map-for-multiple-arguments

  

From functools import partialfrom itertools import repeatfrom multiprocessing import Pool, Freeze_supportdef func (A, B, c) :    print (c)    return a + bdef main ():    A_args = [1, 2, 3]    Second_arg = 1 with    pool () as Pool:        # L = PO Ol.starmap (func, [(1, 1), (2, 1), (3, 1)])        # M = Pool.starmap (func, Zip (A_args, repeat (second_arg)))        N = Pool.map ( Partial (func, b=second_arg,c= "124"), A_args) if __name__ = = "__main__":    freeze_support ()    main ()

  

Use of the starmap of the Python process pools pool

Related Article

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.