joblib那么方便,好用,然而,怎样获取的的当前计算进度呢,以下为pyqt中的解决方式,jupyter请自行查阅tqdm。
===================代码======================
from math import sqrt
from collections import defaultdict
from joblib import Parallel, delayed
mycount = 1
class CallBack(object):
completed = defaultdict(int)
def __init__(self,time,index, parallel):
self.index = index
self.parallel = parallel
def __call__(self, index):
global mycount
CallBack.completed[self.parallel] += 1
mycount = CallBack.completed[self.parallel]
print(f"mycount = {mycount}")
print("done with {}".format(CallBack.completed[self.parallel]))
if self.parallel._original_iterator is not None:
self.parallel.dispatch_next()
import joblib.parallel
joblib.parallel.BatchCompletionCallBack = CallBack
print(Parallel(n_jobs=2)(delayed(sqrt)(i**2) for i in range(10)))
=======感谢外国友人=======
网友评论