This commit is contained in:
Kovid Goyal 2008-03-04 02:59:18 +00:00
parent 2c80dbda83
commit 0aa53a163a

View File

@ -257,7 +257,16 @@ def detect_ncpus():
return ncpus return ncpus
else: else:
#MacOS X #MacOS X
return int(os.popen2("sysctl -n hw.ncpu")[1].read()) try:
return int(subprocess.Popen(('sysctl', '-n', 'hw.cpu'), stdout=subprocess.PIPE).stdout.read())
except IOError: # Occassionally the system call gets interrupted
try:
return int(subprocess.Popen(('sysctl', '-n', 'hw.cpu'), stdout=subprocess.PIPE).stdout.read())
except IOError:
return 1
except ValueError: # On some systems the sysctl call fails
return 1
#for Windows #for Windows
if os.environ.has_key("NUMBER_OF_PROCESSORS"): if os.environ.has_key("NUMBER_OF_PROCESSORS"):
ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]); ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]);