Python TQM进度条和多处理
我试图在我的程序中添加一个进度条,但是,似乎对其他人(在其他帖子上)有效的解决方案对我不起作用 Python版本3.6Python TQM进度条和多处理,python,multiprocessing,tqdm,Python,Multiprocessing,Tqdm,我试图在我的程序中添加一个进度条,但是,似乎对其他人(在其他帖子上)有效的解决方案对我不起作用 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 tq
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操作似乎会带来一些问题。不幸的是,TQM不能与星图一起工作。您可以使用以下选项:
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
不幸的是,TQM不能与星图一起工作。您可以使用以下选项:
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