How call function when async pool has finish execution?

Viewed 44

I am calling a function asynchronously and it gives back a string. I want to save the result into an array and then save the array into a file when all the threads are done processing.

I'm able to save the result, but it's holding my main thread.

for file in sorted(os.listdir(os.path.join(os.getcwd(), 'tempFiles', name)), reverse=True):
    pool.apply_async(self.printer, [r, file, name], callback=self.saveResults)
pool.close()
pool.join()
f = open(os.path.join(os.getcwd(), 'tempFiles', name, 'results.txt'), 'a+')
for r in self.results:
    if r is not None:
        f.write(r)
f.flush()
f.close()

I need some help or direction with this.

0 Answers
Related