【问题标题】:tqdm progress bar and multiprocessingtqdm 进度条和多处理
【发布时间】:2018-10-13 17:14:08
【问题描述】:

我正在尝试在我的程序中添加进度条,但是,似乎适用于其他人(在其他帖子上)的解决方案对我不起作用。

Python 3.6 版。

import multiprocessing as mp
import tqdm

def f(dynamic, fix1, fix2):
    return dynamic + fix1 + fix2

N = 2

fix1 = 5
fix2= 10

dynamic = range(10)

p = mp.Pool(processes = N)

for _ in tqdm.tqdm(p.starmap(f, [(d, fix1, fix2) for d in dynamic]), total = len(dynamic)):
    pass

p.close()
p.join()

知道为什么多处理工作(计算完成),但没有进度条吗?

注意:上面的例子是假的,我的功能不同。

其他问题:如何正确中断多处理程序?我通常在单线程中执行的 ctrl+C 似乎会带来一些问题。

【问题讨论】:

    标签: python multiprocessing tqdm


    【解决方案1】:

    很遗憾,tqdm 不适用于星图。您可以使用以下内容:

    def f(args):
      arg1, arg2 = args
      ... do something with arg1, arg2 ...
    
    
    for _ in tqdm.tqdm(pool.imap_unordered(f, zip(list_of_args, list_of_args2)), total=total):
        pass
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      • 2021-03-08
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多