python psutil.cpu_count() returns CPU 数量错误

python psutil.cpu_count() returns wrong number of cpus

我用slurm分配了32个cpu。但是,当我使用 psutil 中的 cpu_count 函数来获取可用 CPU 的数量时,它 returns 只有 16 个 CPU 可用。为什么 cpu_count returns 比实际的 cpu 数量少?

来自 psutil 的文档

Note that this number is not equivalent to the number of CPUs the current process can actually use. 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.

文档针对您的需求提出了以下建议

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