Query CPU ID from Python?

2024/11/14 18:13:44

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.

Answer

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;
};
https://en.xdnf.cn/q/71929.html

Related Q&A

Recover from segfault in Python

I have a few functions in my code that are randomly causing SegmentationFault error. Ive identified them by enabling the faulthandler. Im a bit stuck and have no idea how to reliably eliminate this pro…

python and using self in methods

From what I read/understand, the self parameter is similiar to this.Is that true?If its optional, what would you do if self wasnt passed into the method?

How to extract only characters from image?

I have this type of image from that I only want to extract the characters.After binarization, I am getting this image img = cv2.imread(the_image.jpg) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) thresh…

connect to Azure SQL database via pyodbc

I use pyodbc to connect to my local SQL database which works withoout problems.SQLSERVERLOCAL=Driver={SQL Server Native Client 11.0};Server=(localdb)\\v11.0;integrated security = true;DATABASE=eodba; c…

Generator function for prime numbers [duplicate]

This question already has answers here:Simple prime number generator in Python(28 answers)Closed 9 years ago.Im trying to write a generator function for printing prime numbers as followsdef getPrimes(n…

`ValueError: too many values to unpack (expected 4)` with `scipy.stats.linregress`

I know that this error message (ValueError: too many values to unpack (expected 4)) appears when more variables are set to values than a function returns. scipy.stats.linregress returns 5 values accord…

Django prefetch_related from foreignkey with manytomanyfield not working

For example, in Django 1.8:class A(models.Model):x = models.BooleanField(default=True)class B(models.Model):y = models.ManyToManyField(A)class C(models.Model):z = models.ForeignKey(A)In this scenario, …

Running SimpleXMLRPCServer in separate thread and shutting down

I have a class that I wish to test via SimpleXMLRPCServer in python. The way I have my unit test set up is that I create a new thread, and start SimpleXMLRPCServer in that. Then I run all the test, and…

Clean Python multiprocess termination dependant on an exit flag

I am attempting to create a program using multiple processes and I would like to cleanly terminate all the spawned processes if errors occur. below Ive wrote out some pseudo type code for what I think …

Any limitations on platform constraints for wheels on PyPI?

Are there any limitations declared anywhere (PEPs or elsewhere) about how broad a scope the Linux wheels uploaded to PyPI should have? Specifically: is it considered acceptable practice to upload li…