I'm using python 2.7 with multiprocessing::Pool to run a job in parallel
I've simplified the example below, but here's the main gist of it.
It will create a file for each person in my dict using the apply_async()
function. However when I check to see if the file was created properly, I notice that sometimes the file was not created.
Now I'm thinking I've done something wrong in how I used multiprocessing::Pool
Any advice?
import os
from multiprocessing import Pool
def outputFile(person):
ofh=open(person+'.txt','w')
ofh.write('test\n')
ofh.close()
pool = Pool(processes=4)
for person in person_dict:
pool.apply_async(outputFile,args(person))
pool.close()
pool.join()
for person in person_dict:
print os.path.isfile(person+'.txt')
True
True
False
True