I am using 'multiprocess.Pool.imap_unordered' as following
from multiprocessing import Pool
pool = Pool()
for mapped_result in pool.imap_unordered(mapping_func, args_iter):
do some additional processing on mapped_result
Do I need to call pool.close
or pool.join
after the for loop?
I had the same memory issue as Memory usage keep growing with Python's multiprocessing.pool when I didn't use
pool.close()
andpool.join()
when usingpool.map()
with a function that calculated Levenshtein distance. The function worked fine, but wasn't garbage collected properly on a Win7 64 machine, and the memory usage kept growing out of control every time the function was called until it took the whole operating system down. Here's the code that fixed the leak:After closing and joining the pool the memory leak went away.
No, you don't, but it's probably a good idea if you aren't going to use the pool anymore.
Reasons for calling
pool.close
orpool.join
are well said by Tim Peters in this SO post: