multiprocessing with large data

后端 未结 3 1868
情深已故
情深已故 2020-12-05 18:34

I am using multiprocessing.Pool() to parallelize some heavy computations.

The target function returns a lot of data (a huge list). I\'m running out of R

3条回答
  •  半阙折子戏
    2020-12-05 18:50

    This sounds like an ideal use case for a Queue: http://docs.python.org/2/library/multiprocessing.html#exchanging-objects-between-processes

    Simply feed your results into the queue from the pooled workers and ingest them in the master.

    Note that you still may run into memory pressure issues unless you drain the queue nearly as fast as the workers are populating it. You could limit the queue size (the maximum number of objects that will fit in the queue) in which case the pooled workers would block on the queue.put statements until space is available in the queue. This would put a ceiling on memory usage. But if you're doing this, it may be time to reconsider whether you require pooling at all and/or if it might make sense to use fewer workers.

提交回复
热议问题