美文网首页
获取joblib并行运算中的进度 python 并行计算

获取joblib并行运算中的进度 python 并行计算

作者: 昵称违法 | 来源:发表于2019-10-23 14:55 被阅读0次

    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)))
    

    =======感谢外国友人=======

    相关文章

      网友评论

          本文标题:获取joblib并行运算中的进度 python 并行计算

          本文链接:https://www.haomeiwen.com/subject/itrkvctx.html