Reputation: 151
Please advise how can I keep order while using multiprocessing in Python. Both func and somefunc return lists. Thanks,
results = []
def callback(*args): results.append(*args)
def in_parallel(fn, func):
print 'Process started on',time.strftime('%H:%M:%S')
pool = mp.Pool(processes = 4)
for num, i in enumerate(somefunc(fn)):
pool.apply_async(func, args = (i,), callback = callback([num, callback]))
pool.close()
pool.join()
return results
Upvotes: 2
Views: 872
Reputation: 151
The problem has been solved with the following:
r = pool.map_async(...)
r.wait()
Upvotes: 1