I'm trying to detect the number of non-HyperThreading cores on a machine using a cross-platform method.
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.
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.Note that in the remarks section the Microsoft documentation states:
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
is different, hyperthreading is enabled.
platform independent and in python standard library:
For a platform-independent method, see the python bindings to hwloc:
hwloc is designed to be portable across OSes and architectures.