Counting processors

P

Pauldoo

Hi,
Is a way in python to obtain the total number of processors present in
the system?

os.platform doesn't seem to contain anything useful.
 
W

wittempj

I don't think there is direct method. On Linux you can inspect file
/proc/cpuinfo to determine the installed cpus.
 
B

Benji York

Pauldoo said:
Is a way in python to obtain the total number of processors present in
the system?

I don't know of a platform independent way. If you specify one or more
platforms, I'm sure someone will be able to help.
 
P

Pauldoo

Yeh well I know of /proc/cpuinfo (due to linux's hacked up non-unix
/proc, *grumble*) and the NUMBER_OF_PROCESSORS environment variable on
windows. I was just hoping for a slightly more platform independant
way of doing it.
 
M

MrJean1

Or maybe

os.sysconf('SC_NPROCESSORS_ONLN')

Usually, the value returned by os.sysconf('SC_NPROCESSORS_ONLN') and
os.sysconf('SC_NPROCESSORS_CONF') are the same, but if they do differ,
os.sysconf('SC_NPROCESSORS_ONLN') is the reliably figure.


/Jean Brouwers

PS) This applies to Linux and Solaris, at least.
 
M

Mike Meyer

k pur said:
You can use

print os.sysconf("SC_NPROCESSORS_CONF")

works on Linux

Works on FreeBSD as well. It hooks up to the sysconf C call. That's a
Posix call, so this should work portably across Posix systems. I know
Windows can be made Posix compliant, but I'm no sure how much of that
functionality you get out of the box.

<mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,310
Members
47,977
Latest member
MillaDowdy

Latest Threads

Top