On 10/6/07, Lawrence Oluyede <[EMAIL PROTECTED]> wrote: > John <[EMAIL PROTECTED]> 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)? > > >From processing <http://cheeseshop.python.org/pypi/processing/0.34> :
A few reiterated notes inline, from my previous message. > def cpuCount(): > ''' > Returns the number of CPUs in the system > ''' > if sys.platform == 'win32': > try: > num = int(os.environ['NUMBER_OF_PROCESSORS']) The user can do bad things to this environment variable, but it's probably ok most of the time. (Hey, they change it, they pay the consequences). > else: > try: > num = os.sysconf('SC_NPROCESSORS_ONLN') This is really bad on linux. You really want to parse /proc/cpuinfo because HT 'cpus' are almost useless, and can be bad in situations where you try to treat them as general purpose cpus. -- Nick -- http://mail.python.org/mailman/listinfo/python-list