It cost me a whole night to debug my code, and I finally found this tricky problem. Please take a look at the code below.
from multiprocessing import Pool
def myfunc(x):
return [i for i in range(x)]
pool=Pool()
A=[]
r = pool.map_async(myfunc, (1,2), callback=A.extend)
r.wait()
I thought I would get A=[0,0,1]
, but the output is A=[[0],[0,1]]
. This does not make sense to me because if I have A=[]
, A.extend([0])
and A.extend([0,1])
will give me A=[0,0,1]
. Probably the callback works in a different way. So my question is how to get A=[0,0,1]
instead of [[0],[0,1]]
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…