How can I check nbr of cores of computer?

Dan Upton upton at
Wed Jul 30 20:16:32 CEST 2008

On Wed, Jul 30, 2008 at 2:22 PM, John Nagle <nagle at> wrote:
> defn noob wrote:
>> How can I check how many cores my computer has?
>> Is it possible to do this in a Python-app?
>    Why do you care?  Python can't use more than one of them at
> a time anyway.

Per Python process, but you might fork multiple processes and want to
know how many cores there are to know how many to fork, and which
cores to pin them to.  (I don't know if there's a direct way in Python
to force it to a certain core, so I instead just wrote an extension to
interface with sched_setaffinity on Linux.)

On Linux, an almost assuredly non-ideal way to find out the number of
cores is to read /proc/cpuinfo and look for the highest-numbered
"processor: " line (and add 1).

More information about the Python-list mailing list