Python 多处理:进程的进度报告
我的应用程序中有一些任务受 CPU 限制,并且我想使用多处理模块来使用多核处理器。 我接受一个大任务(视频文件分析),并将其分成几个较小的任务,这些任务放入队列中并由工作进程完成。 我想知道的是如何从这些工作进程向主进程报告进度。例如,我需要他们发送“我对文件 1 的分析处于 1000 毫秒”。制作此类进度报告的最佳方式是什么?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会推荐 multiprocessing.Queue:没有什么比工作进程更简单的了在那里发布他们的更新(大概是作为进度更新各个方面的元组),而主进程只是等待这些消息,当它们到来时更新 GUI(或文本 UI;-)以让用户评估进度。
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.