本文介绍了在多处理中使用pool.join,pool.close的目的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的链接中,对Pool类的map方法进行了说明.

In the link below there is an explanation of the map method on the Pool class.

似乎阻塞,直到结果准备好为止.这意味着在运行pool.map之后无需执行pool.close(); pool.join(),但是在博客.

It seems that it blocks until the result is ready. This implies that there is no need to do pool.close(); pool.join() after running pool.map, however it is demo'd in this way in this blog.

我丢失了某些东西还是在运行pool.map之后需要做pool.close(与pool.map_async相反??请注意,我使用的是[multiprocessing.dummy][2],它提供了与多处理类似的api,但是使用了线程在幕后.

Am I missing something or is there a need to do pool.close after running pool.map (as opposed to pool.map_async? Note I am using [multiprocessing.dummy][2], which is provides a similar api to multiprocessing, but uses threading under the covers.

https://docs.python. org/2/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool.map

推荐答案

pool.close告诉池不接受任何新作业.

pool.close tells the pool not to accept any new job.

pool.join通知池等待所有作业完成然后退出,从而有效清理池.

pool.join tells the pool to wait until all jobs finished then exit, effectively cleaning up the pool.

所以阻止父进程只是pool.join正在执行的副作用.

So blocking the parent process is just a side effect of what pool.join is doing.

的确,当您调用pool.map()时,父进程被阻塞,直到map返回结果.但是,在使用closejoin pool之后,这是一个好习惯,以便更好地管理资源和控制异常.

It's true that when you call pool.map(), the parent process is blocked until map returns result. But it's a good practice to close and join the pool after using it, to better manage resource and control exceptions.

这篇关于在多处理中使用pool.join,pool.close的目的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 02:24