ProcessPoolExecutor中如何停止进程之间的等待时间

问题描述

我有一项艰巨的任务要处理大约 2000 个长视频。 我的代码是这样的:

ctx = mp.get_context("spawn")  # It is neccessary to GPU in multiple process.
pool = concurrent.futures.ProcesspoolExecutor(max_workers=4,mp_context=ctx)
results = []

for file in tqdm(files):
    r = pool.submit(VideoProcessing,(file))
    results.append(r)
    
for r in result:
    print(r.result)

VideoProcessing 是处理视频文件功能,需要 GPU 来加速。所以为了开始代码,我为 GPU 设置了 MPS 模型。

nvidia-cuda-mps-control -d

一开始它在 Linux 中运行得很快。但是过了一段时间。变得很慢,开始新文件前等待的时间越来越长。

我想知道如何让代码直接处理新文件并停止等待。

提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)