here is my code
from multiprocessing import Pool
a = []
def f(x):
a.append(x*x)
return x*x
if __name__ == '__main__':
with Pool(5) as p:
print(p.map(f, [1, 2, 3]))
print(a)
I would expect print(a)
to output [1,4,9]
. However, it just outputs an empty array. Is there a way to easily fix this, ideally allowing f()
to access a
?