Append to empty list with multiprocessing pool

36 Views Asked by At

From a broader level, this is what I am trying to do - append to an empty list an item it reads from the elements list with multiprocessing pool, but this is printing an empty list. Any idea where I am going wrong, or any alternative to achieve the same task in parallel?

import numpy as np
from multiprocess import Pool

empty = []

elements = np.arange(10)

def fill_list(element):
    empty.append(element)

with Pool(5) as p:
    p.map(fill_list, elements)
    
print(empty)
0

There are 0 best solutions below