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 .我正在尝试学习如何使用 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章