Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query CPU ID from Python?

How I can find processor id with py2.6, windows OS?

I know that there is pycpuid, but I can't compile this under 2.6.

like image 408
Derek Avatar asked Jun 16 '10 19:06

Derek


3 Answers

Have you tried wmi? (It may require elevated privilege level)

Here's a solution (it works for Python 2 and 3):

>>> import wmi
>>> c = wmi.WMI()
>>> for s in c.Win32_Processor():
    print (s)



instance of Win32_Processor
{
    AddressWidth = 64;
    Architecture = 9;
    Availability = 3;
    Caption = "Intel64 Family 6 Model 26 Stepping 5";
    CpuStatus = 1;
    CreationClassName = "Win32_Processor";
    CurrentClockSpeed = 3068;
    DataWidth = 64;
    Description = "Intel64 Family 6 Model 26 Stepping 5";
    DeviceID = "CPU0";
    ExtClock = 133;
    Family = 1;
    L2CacheSize = 1024;
    L3CacheSize = 8192;
    L3CacheSpeed = 0;
    Level = 6;
    LoadPercentage = 3;
    Manufacturer = "GenuineIntel";
    MaxClockSpeed = 3068;
    Name = "Intel(R) Core(TM) i7 CPU         950  @ 3.07GHz";
    NumberOfCores = 4;
    NumberOfLogicalProcessors = 8;
    PowerManagementSupported = FALSE;
    ProcessorId = "BFEBFBFF000106A5";
    ProcessorType = 3;
    Revision = 6661;
    Role = "CPU";
    SocketDesignation = "CPU 1";
    Status = "OK";
    StatusInfo = 3;
    SystemCreationClassName = "Win32_ComputerSystem";
    SystemName = "RYAN-PC";
    UpgradeMethod = 1;
    Version = "";
    VoltageCaps = 0;
};
like image 118
Ryan Ginstrom Avatar answered Oct 15 '22 16:10

Ryan Ginstrom


I've found that the wmic command is always available on Windows-XP, and use subprocess.Popen to run it, rather than require my users to install any special Python packages.

C:\>wmic cpu get ProcessorId /format:csv

Node,ProcessorId
E100325,BFEBFBFF00000F43
E100325,BFEBFBFF00000F43
like image 23
RobM Avatar answered Oct 15 '22 15:10

RobM


You can get CPU ID from WMI . VBScript Sample here You can use WMI from Python.
Combining these two resources I think you can figure out the rest.

like image 43
renick Avatar answered Oct 15 '22 14:10

renick