python 多參數並行化

multiprocessing模塊與map方法ip

import timeit

from datetime import datetimeimport

from multiprocessing.dummy import Pool as ThreadPooldate

from functools import partialmap

 

 

def add(x, y):方法

    print(datetime.now(), "enter add func...")im

    time.sleep(2)datetime

    print(datetime.now(), "leave add func...")tools

    return x+yprocess

 

 

def add_wrap(args):

    add(*args)

    return

 

 

if __name__ == "__main__":

    pool = ThreadPool(4) # 池的大小爲4

    print(pool.map(add_wrap, [(1,2),(3,4),(5,6)]))

    #close the pool and wait for the worker to exit

    pool.close()

    pool.join()

相關文章
相關標籤/搜索