Here is the code I am trying to do. The output text file should contain 500 data. But it is always less than 500 (450 or 476 or 429 when I run). Any idea why this is happening and what should I do to get 500 data in output. It will be very helpful if I get output in order.
def foo(j):
output=[j]
f=open('output.txt','a')
f.write('\n')
np.savetxt(f,output)
f.close()
if __name__=='__main__':
pool = Pool(processes=4)
pool.map(foo,range(500))