I am trying to use a multiprocessing Pool
without a return value for parallel calculation. It could be faster if there's no need to return and retrieve values from the subprocess. Is there a way to do that?
Here is a simple example:
from multiprocessing import Pool
def fun(a):
# do something..
a["1"]=100
a={
"1":12
}
multi = [a] * 10
p = Pool(4)
p.map(fun, multi)
data = [a["1"] for a in multi]
print(data)
>>> [12, 12, 12, 12, 12, 12, 12, 12, 12, 12]
[fun(a) for a in multi]
data = [a["1"] for a in multi]
print(data)
>>> [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]
Does anybody know why? And is there a solution for that?