简体   繁体   English

python psutil.cpu_count()返回错误的cpus数

[英]python psutil.cpu_count() returns wrong number of cpus

I used slurm to allocated 32 cpus. 我用口吃来分配32个CPU。 However, when I use cpu_count functions from psutil to get the number of available cpus, it returns only 16 cpus available. 但是,当我使用psutil中的cpu_count函数获取可用cpus的数量时,它仅返回16 cpus可用。 Why cpu_count returns less number than actual number of cpus? 为什么cpu_count返回的数字少于实际的cpus?

From the docs of psutil 来自psutil的文档

Note that this number is not equivalent to the number of CPUs the current process can actually use. 请注意,此数目不等于当前进程实际可以使用的CPU数目。 That can vary in case process CPU affinity has been changed, Linux cgroups are being used or on Windows systems using processor groups or having more than 64 CPUS. 如果更改了进程CPU亲和力,正在使用Linux cgroup或在使用处理器组或具有64个以上CPU的Windows系统上,这可能会有所不同。

The docs suggest the following for what you want 该文档建议以下您想要的

>>> len(psutil.Process().cpu_affinity())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM