从python多处理模块中的进程池中获取工人数量 [英] Get number of workers from process Pool in python multiprocessing module

查看:42
本文介绍了从python多处理模块中的进程池中获取工人数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来直接从 Python 中的 multiprocessing.Pool 类的实例中获取进程数.. 有没有办法做到这一点?

文档没有显示任何相关内容.

谢谢

解决方案

您可以使用 _processes 属性:

<预><代码>>>>导入多处理>>>池 = multiprocessing.Pool()>>>pool._processes8

multiprocessing.cpu_count()<的返回值相同/a> 除非您在创建 Pool 对象时指定了进程数.

<预><代码>>>>multiprocessing.cpu_count()8

I am trying to figure a way to get the number of processes directly from an instance of multiprocessing.Pool class in Python.. Is there a way to do it?

The documentation doesn't show anything related.

Thanks

解决方案

You can use _processes attribute:

>>> import multiprocessing
>>> pool = multiprocessing.Pool()
>>> pool._processes
8

The return value is same for multiprocessing.cpu_count() unless you specified process count when creating Pool object.

>>> multiprocessing.cpu_count()
8

这篇关于从python多处理模块中的进程池中获取工人数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆