Python:用于检测物理非HT CPU的跨平台解决方案? [英] Python: Cross-platform solution to detect physical non-HT CPUs?

查看:62
本文介绍了Python:用于检测物理非HT CPU的跨平台解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用跨平台方法检测计算机上非超线程内核的数量.

I'm trying to detect the number of non-HyperThreading cores on a machine using a cross-platform method.

Multiprocessing的 cpu_count 仅检测到总数处理器的数量,我可以在Linux机器上的grep/proc/cpuinfo中找到答案.但是,我正在寻找Windows解决方案.

Multiprocessing's cpu_count only detects the total number of processors, and I can grep /proc/cpuinfo on Linux machines to find the answer. However, I'm looking for a Windows solution.

此新闻组线程有所帮助,但我仍然尚未找到答案.

This newsgroup thread helped a little, but I still haven't found the answer.

推荐答案

您可以使用Tim Golden的WMI绑定来访问有关Windows上CPU的wmi信息.请参见蒂姆的wmi模块食谱.您可能想使用Win32_Processor类-请参阅 Microsoft文档

You can use Tim Golden's WMI bindings to access wmi information about CPUs on Windows. See Tim's wmi module cookbook. You probabably want to use the Win32_Processor class -- see the Microsoft documentation.

请注意,Microsoft文档在备注部分中声明:

Note that in the remarks section the Microsoft documentation states:

要确定是否为处理器启用了超线程,请比较NumberOfLogicalProcessors和NumberOfCores.如果在BIOS中为处理器启用了超线程,则NumberOfCores小于NumberOfLogicalProcessors.例如,包含两个启用了超线程的处理器的双处理器系统可以运行四个线程或程序,也可以同时运行.在这种情况下,NumberOfCores为2,NumberOfLogicalProcessors为4.

To determine if hyperthreading is enabled for the processor, compare NumberOfLogicalProcessors and NumberOfCores. If hyperthreading is enabled in the BIOS for the processor, then NumberOfCores is less than NumberOfLogicalProcessors. For example, a dual-processor system that contains two processors enabled for hyperthreading can run four threads or programs or simultaneously. In this case, NumberOfCores is 2 and NumberOfLogicalProcessors is 4.

Dag Wieer的博客显示一种在Linux上从/proc/cpuinfo提取超线程信息的方法.

Dag Wieer's blog shows a way of extracting hyperthreading info from /proc/cpuinfo on Linux.

我认为,如果第一行和第二行的输出

I think, if the output of the first and second lines of

cat /proc/cpuinfo | egrep 'physical|processor' | grep -v sizes | \
                    tail -n2 | cut -d : -f 2`

不同,启用了超线程.

这篇关于Python:用于检测物理非HT CPU的跨平台解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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