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