multiprocessing.Pool: What’s the difference between map_async and imap?

I’m trying to learn how to use Python’s multiprocessing package, but I don’t understand the difference between map_async and imap.
I noticed that both map_async and imap are executed asynchronously. So when should I use one over the other? And how should I retrieve the result returned by map_async?

Should I use something like this?

def test():
    result = pool.map_async()
    pool.close()
    pool.join()
    return result.get()

result=test()
for i in result:
    print i

2 Answers
2

Leave a Comment