Cross platform way of finding number of processors on a machine?
Kay Schluehr
kay.schluehr at gmx.net
Fri Oct 5 04:09:19 EDT 2007
On 5 Okt., 09:58, Tim Golden <m... at timgolden.me.uk> wrote:
> Nicholas Bastin wrote:
> > On 10/4/07, John <weekender... at yahoo.com> 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:
>
> http://msdn2.microsoft.com/en-us/library/aa394373.aspx
>
> 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.
>
> TJG
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']
2
However this feature might not be guaranteed by Microsoft for
arbitrary computers using their OS?
Kay
More information about the Python-list
mailing list