问题:
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