Answer the question
In order to leave comments, you need to log in
How to organize iterative-recursive parallel processing?
Available:
pool = Pool(num_workers)
for r in pool.map(data_handler, data_input_iter, num_workers): pass
queue = Queue(num_workers)
for datum in data_input_iter:
queue.put(datum, block=True)
Answer the question
In order to leave comments, you need to log in
In general, it turned out like this parsley.
How viable is yet to be seen.
class Worker():
def __init__(self, consumer, queue):
self.consumer = consumer
self.queue = queue
def __call__(self, inp):
if inp is None:
return
res = self.consumer(inp)
if res is not None:
for r in res:
self.queue.put(r)
def multiprocess(producer, consumer, num_workers):
pool = mp.Pool(num_workers)
queue = mp.Manager().Queue()
worker = Worker(consumer, queue)
for _ in pool.imap_unordered(worker, producer, num_workers):
while not queue.empty():
pool.apply(worker, (queue.get(),))
pool.close()
pool.join()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question