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

后端 未结 6 681
轮回少年
轮回少年 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 01:52

    Just put range(10) inside tqdm(...)! It probably seemed too good to be true for you, but it really works (on my machine):

    from math import sqrt
    from joblib import Parallel, delayed  
    from tqdm import tqdm  
    result = Parallel(n_jobs=2)(delayed(sqrt)(i ** 2) for i in tqdm(range(100000)))
    

提交回复
热议问题