summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing
diff options
context:
space:
mode:
authorCharles-Francois Natali <cf.natali@gmail.com>2013-05-20 12:40:46 (GMT)
committerCharles-Francois Natali <cf.natali@gmail.com>2013-05-20 12:40:46 (GMT)
commit44feda3cd0454cd00028e09f3151de67e8aad76f (patch)
treea96b037934976f43273b9c6347b2cf098e7bb813 /Lib/multiprocessing
parent93c6770c7202ea8c123a1d04e76be1007584697e (diff)
downloadcpython-44feda3cd0454cd00028e09f3151de67e8aad76f.zip
cpython-44feda3cd0454cd00028e09f3151de67e8aad76f.tar.gz
cpython-44feda3cd0454cd00028e09f3151de67e8aad76f.tar.bz2
Issue #17914: Add os.cpu_count(). Patch by Yogesh Chaudhari, based on an
initial patch by Trent Nelson.
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r--Lib/multiprocessing/__init__.py25
1 files changed, 3 insertions, 22 deletions
diff --git a/Lib/multiprocessing/__init__.py b/Lib/multiprocessing/__init__.py
index b5f16d7..b42613f 100644
--- a/Lib/multiprocessing/__init__.py
+++ b/Lib/multiprocessing/__init__.py
@@ -85,30 +85,11 @@ def cpu_count():
'''
Returns the number of CPUs in the system
'''
- if sys.platform == 'win32':
- try:
- num = int(os.environ['NUMBER_OF_PROCESSORS'])
- except (ValueError, KeyError):
- num = 0
- elif 'bsd' in sys.platform or sys.platform == 'darwin':
- comm = '/sbin/sysctl -n hw.ncpu'
- if sys.platform == 'darwin':
- comm = '/usr' + comm
- try:
- with os.popen(comm) as p:
- num = int(p.read())
- except ValueError:
- num = 0
+ num = os.cpu_count()
+ if num is None:
+ raise NotImplementedError('cannot determine number of cpus')
else:
- try:
- num = os.sysconf('SC_NPROCESSORS_ONLN')
- except (ValueError, OSError, AttributeError):
- num = 0
-
- if num >= 1:
return num
- else:
- raise NotImplementedError('cannot determine number of cpus')
def freeze_support():
'''