Multiprocessing in a pipeline done right

后端 未结 6 1245
长情又很酷
长情又很酷 2021-02-04 05:06

I\'d like to know how multiprocessing is done right. Assuming I have a list [1,2,3,4,5] generated by function f1 which is written to a Queue

6条回答
  •  無奈伤痛
    2021-02-04 05:51

    What would be wrong with using idea 1, but with each worker process (f2) putting a custom object with its identifier when it is done? Then f3, would just terminate that worker, until there was no worker process left.

    Also, new in Python 3.2 is the concurrent.futures package on the standard library, that should do what you are trying to in the "right way" (tm) - http://docs.python.org/dev/library/concurrent.futures.html

    Maybe it is possible to find a backport of concurrent.futures to Python 2.x series.

提交回复
热议问题