I have a following piece of code.
My worker returns a list and I want a master list which is union of all the list.
from multiprocessing import Pool, Manager
manager = Manager()
another_shared_list = manager.list()
def worker2(number):
return [x for x in xrange(number)]
numbers = [5,7,2,4]
pool1 = Pool(4)
another_shared_list.extend(pool1.map(worker2, numbers))
print another_shared_list
It prints
[[0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5, 6], [0, 1], [0, 1, 2, 3]]
As you might have probably guessed I want another_shared_list to be
[0,1,2,3,4,0,1,2,3,4,5,6,0,1,0,1,2,3]
How should I approach it?
edit: I know it seems like a flattening the list question not for multiprocessing. But my preference would be to avoid itertools. I want something such that another_shared_list directly gets the flattened list from the call pool1.map or something else!!