How can I get cpuinfo in python 2.4. I want to determine number of processors in a machine. (The code should be OS independent). I have written the code for Linux, but don't know how to make it work for windows.
import subprocess, re
cmd = 'cat /proc/cpuinfo |grep processor |wc'
d = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
lines = d.stdout.readlines()
lines = re.split('\s+', lines[0])
number_of_procs = int(lines[1])
Assuming that I don't have cygwin installed on windows machine, I just have python2.4. Please let me know if there's some module which can be called for this purpose, or any help to write the code for this functionality.
Thanks, Sandhya
Here's on old solution written by Bruce Eckel that should work on all major platforms: http://codeliberates.blogspot.com/2008/05/detecting-cpuscores-in-python.html