Cross platform way of finding number of processors on a machine?

Kay Schluehr kay.schluehr at
Fri Oct 5 10:09:19 CEST 2007

On 5 Okt., 09:58, Tim Golden <m... at> wrote:
> Nicholas Bastin wrote:
> > On 10/4/07, John <weekender... at> wrote:
> >> Is there a way to find the number of processors on a machine (on linux/
> >> windows/macos/cygwin) using python code (using the same code/cross
> >> platform code)?
> > There's no single call that will give you the same info on every
> > platform, but you can obviously write this yourself and switch based
> > on os.uname()[0] in most cases.
> Second that point about not getting one cross-platform
> answer. Under Windows, WMI is often the way to go for
> these things:
> but, as Nicholas noted:
>    """
>    Windows Server 2003, Windows XP, and Windows 2000:
>      This property is not available.
>    """
> since it's presumably not available in anything earlier either,
> that leaves you with Vista or the early-adopter editions of the
> next Windows Server product.

Remarkable. I've a two years old Windows XP dual core notebook and
when I'm asking Python I get the correct answer:

>>> import os
>>> os.environ['NUMBER_OF_PROCESSORS']

However this feature might not be guaranteed by Microsoft for
arbitrary computers using their OS?


More information about the Python-list mailing list