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

10/14 02:01
阅读数 0

问题:

I'm trying to learn how to use Python's multiprocessing package, but I don't understand the difference between map_async and imap .我正在尝试学习如何使用 Python 的multiprocessing包,但我不明白map_asyncimap之间的区别。 I noticed that both map_async and imap are executed asynchronously.我注意到map_asyncimap都是异步执行的。 So when should I use one over the other?那么我什么时候应该使用一个? And how should I retrieve the result returned by map_async ?我应该如何检索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

解决方案:

参考一: https://en.stackoom.com/question/1nHGX
参考二: https://stackoom.com/question/1nHGX
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部