Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (27 sloc) 920 Bytes
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at
import os
def cpuCount():
A version of cpu_count() that seems compatible with Python 2.5
# POSIX platforms
if hasattr(os, 'sysconf'):
if os.sysconf_names.has_key('SC_NPROCESSORS_ONLN'):
# Linux
cpuNum = os.sysconf('SC_NPROCESSORS_ONLN')
if cpuNum > 0 and isinstance(cpuNum, int):
return cpuNum
# Mac OS X
return int(os.popen2('sysctl -n hw.ncpu')[1].read())
# Windows
if os.environ.has_key('NUMBER_OF_PROCESSORS'):
cpuNum = int(os.environ['NUMBER_OF_PROCESSORS']);
if cpuNum > 0:
return cpuNum
# Return 1 by default
return 1
Jump to Line
Something went wrong with that request. Please try again.