Ending data exchange through multiprocessing pipe

Scott David Daniels Scott.Daniels at Acm.Org
Wed Apr 22 16:30:33 EDT 2009


Michal Chruszcz wrote:
> ... First idea, which came to my mind, was using a queue. I've got many
> producers (all of the workers) and one consumer. Seams quite simple,
> but it isn't, at least for me. I presumed that each worker will put()
> its results to the queue, and finally will close() it, while the
> parent process will get() them as long as there is an active
> subprocess....

Well, if the protocol for a worker is:
     <someloop>:
          <calculate>
          queue.put(result)
     queue.put(<worker_end_sentinel>)
     queue.close()


Then you can keep count of how many have finished in the consumer.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list