問題:
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_async
和imap
之間的區別。 I noticed that both map_async
and imap
are executed asynchronously.我注意到map_async
和imap
都是異步執行的。 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