How can we use tqdm in a parallel execution with joblib?

后端 未结 6 660
轮回少年
轮回少年 2021-02-05 01:25

I want to run a function in parallel, and wait until all parallel nodes are done, using joblib. Like in the example:

from math import sqrt
from joblib import Par         


        
6条回答
  •  梦谈多话
    2021-02-05 02:06

    I've created pqdm a parallel tqdm wrapper with concurrent futures to comfortably get this done, give it a try!

    To install

    pip install pqdm
    

    and use

    from pqdm.processes import pqdm
    # If you want threads instead:
    # from pqdm.threads import pqdm
    
    args = [1, 2, 3, 4, 5]
    # args = range(1,6) would also work
    
    def square(a):
        return a*a
    
    result = pqdm(args, square, n_jobs=2)
    

提交回复
热议问题