summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharles-François Natali <cf.natali@gmail.com>2013-06-28 17:25:45 (GMT)
committerCharles-François Natali <cf.natali@gmail.com>2013-06-28 17:25:45 (GMT)
commit37cfb0a920bd01ee81ce7bebebfe510d01d751d6 (patch)
treefdbb1f0eee3f4f5addd815279af456aa686dccf5
parentc723da361a8d5129ec9bd336e6327a65b4e92148 (diff)
downloadcpython-37cfb0a920bd01ee81ce7bebebfe510d01d751d6.zip
cpython-37cfb0a920bd01ee81ce7bebebfe510d01d751d6.tar.gz
cpython-37cfb0a920bd01ee81ce7bebebfe510d01d751d6.tar.bz2
Issue #17914: Use os.cpu_count() instead of multiprocessing.cpu_count() where
applicable.
-rw-r--r--Doc/library/multiprocessing.rst2
-rw-r--r--Lib/concurrent/futures/process.py2
-rw-r--r--Lib/multiprocessing/pool.py8
-rwxr-xr-xLib/test/regrtest.py8
4 files changed, 7 insertions, 13 deletions
diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst
index 2c1ec9b..95d1b1f 100644
--- a/Doc/library/multiprocessing.rst
+++ b/Doc/library/multiprocessing.rst
@@ -1664,7 +1664,7 @@ with the :class:`Pool` class.
callbacks and has a parallel map implementation.
*processes* is the number of worker processes to use. If *processes* is
- ``None`` then the number returned by :func:`cpu_count` is used. If
+ ``None`` then the number returned by :func:`os.cpu_count` is used. If
*initializer* is not ``None`` then each worker process will call
``initializer(*initargs)`` when it starts.
diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py
index 3c20b93..abb99d6 100644
--- a/Lib/concurrent/futures/process.py
+++ b/Lib/concurrent/futures/process.py
@@ -331,7 +331,7 @@ class ProcessPoolExecutor(_base.Executor):
_check_system_limits()
if max_workers is None:
- self._max_workers = multiprocessing.cpu_count()
+ self._max_workers = os.cpu_count() or 1
else:
self._max_workers = max_workers
diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py
index bcf8a37..8082ad6 100644
--- a/Lib/multiprocessing/pool.py
+++ b/Lib/multiprocessing/pool.py
@@ -17,10 +17,11 @@ import threading
import queue
import itertools
import collections
+import os
import time
import traceback
-from multiprocessing import Process, cpu_count, TimeoutError
+from multiprocessing import Process, TimeoutError
from multiprocessing.util import Finalize, debug
#
@@ -147,10 +148,7 @@ class Pool(object):
self._initargs = initargs
if processes is None:
- try:
- processes = cpu_count()
- except NotImplementedError:
- processes = 1
+ processes = os.cpu_count() or 1
if processes < 1:
raise ValueError("Number of processes must be at least 1")
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index e6eef16..bd816dd 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -508,12 +508,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
elif o in ('-j', '--multiprocess'):
use_mp = int(a)
if use_mp <= 0:
- try:
- import multiprocessing
- # Use all cores + extras for tests that like to sleep
- use_mp = 2 + multiprocessing.cpu_count()
- except (ImportError, NotImplementedError):
- use_mp = 3
+ # Use all cores + extras for tests that like to sleep
+ use_mp = 2 + (os.cpu_count() or 1)
if use_mp == 1:
use_mp = None
elif o == '--header':