Python多重处理:来自流程的进度报告 [英] Python multiprocessing : progress report from processes
问题描述
我在应用程序中有一些任务受CPU限制,我想使用多处理模块来使用多核处理器. 我承担了一项大任务(视频文件分析),并将其拆分为几个较小的任务,这些任务被放入队列并由工作进程完成. 我想知道的是如何从这些工作进程报告主要进程的进度.例如,我需要他们发送我在对文件1的分析的1000ms之内".制作此类进度报告的最佳方法是什么?
I have some tasks in an application that are CPU bound and I want to use the multiprocessing module to use the multi-cores processors. I take a big task (a video file analysis) and I split it into several smaller tasks which are put in a queue and done by worker processes. What I want to know is how to report progress to the main process from these worker processes. For example I need them to send "I am at 1000ms of my analysis of file 1". What is the best way to do such progress reports ?
推荐答案
I would recommend a multiprocessing.Queue: nothing easier than for the worker processes to post their updates (presumably as tuples with the various aspect of their progress updates) there, while the main process just wait for such messages and when they come updates the GUI (or textual UI;-) to keep the user appraised of progress.
这篇关于Python多重处理:来自流程的进度报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!