How can I check nbr of cores of computer?

Duncan Booth duncan.booth at invalid.invalid
Thu Jul 31 10:11:33 CEST 2008

Steven D'Aprano <steve at> wrote:

> I don't expect that Python will have a built-in core-counting function. 
> You would probably need to ask the operating system. On Linux, you could 
> do this:
> import os
> text = os.popen('cat /proc/cpuinfo').read()
> How you would do it in Windows or Mac, I have no idea.

One way on windows:

>>> import win32pdhutil
>>> def howmanycores():
    for i in range(9999):
        try: win32pdhutil.GetPerformanceAttributes("Processor(%d)" % i,"% 
Processor Time")
        except: break
    return i

>>> print howmanycores()

Duncan Booth

More information about the Python-list mailing list