tqdm 进度条和多处理

编程入门 行业动态 更新时间:2024-10-28 07:27:59
本文介绍了tqdm 进度条和多处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I'm trying to add a progression bar to my program, however, solutions that seems to works for other (on other posts) do not work for me.

Python 3.6 版.

Python version 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()

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

Any idea why the multiprocessing works (the computation is done), but there is no progress bar?

注意:上面的例子是虚拟的,我的功能不同.

NB: The example above is dummy, my function are different.

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

Other question: how can I interrupt properly a multiprocessing program? The ctrl+C that I usually do in signle thread seems to pose some issues.

推荐答案

不幸的是,tqdm 不能与 starmap 一起使用.您可以使用以下内容:

Unfortunately, tqdm is not working with starmap. You can use the following:

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

更多推荐

tqdm 进度条和多处理

本文发布于:2023-11-23 09:48:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620995.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多处   进度条   tqdm

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!