pool.imap_unordered()多进程模块使用

很简单的使用代码:

from multiprocess import Pool

pool = Pool(args.n_cpus)

# eg: f_list = [a, b, c]

for a in pool.imap_unordered(f, f_list):
    # Some unrelated code

pool.close()
pool.join()

def f(a):
    # Some unrelated code 
    return a

OR 

from multiprocess import Pool

# eg: f_list = [a, b, c]

with Pool() as pool:
    for a in pool.imap_unordered(f, f_list):
        # Some unrelated code

def f(a):
    # Some unrelated code 
    return a

讲解详见:https://www.jianshu.com/p/4c4ca5bccc09

你可能感兴趣的:(pool.imap_unordered()多进程模块使用)