What are the advantages of concurrent.futures over multiprocessing in Python?

大城市里の小女人 提交于 2019-11-30 13:43:23

问题


I'm writing an app in Python and I need to run some tasks simultaneously. The module multiprocessing offers the class Process and the concurrent.futures module has the class ProcessPoolExecutor. Both seem to use multiple processes to execute their tasks, but their APIs are different. Why should I use one over the other?

I know that concurrent.futures was added in Python 3, so I guess it's better?


回答1:


The motivations for concurrent.futures are covered in the PEP.

In my practical experience concurrent.futures provides a more convenient programming model for long-running task submission and monitoring situations. A program I recently wrote using concurrent.futures involved monitoring a directory for incoming files over a 2-3 hour window, translating each file as it arrives to a task, submitting it and so on. Future objects returned by the ProcessPoolExecutor allow for tracking task status, providing intermediate status reports etc in a convenient way.



来源:https://stackoverflow.com/questions/11617619/what-are-the-advantages-of-concurrent-futures-over-multiprocessing-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!