cpython: 6a0437adafbd (original) (raw)
Mercurial > cpython
changeset 84355:6a0437adafbd
Issue #17914: Use os.cpu_count() instead of multiprocessing.cpu_count() where applicable. [#17914]
Charles-François Natali cf.natali@gmail.com | |
---|---|
date | Fri, 28 Jun 2013 19:25:45 +0200 |
parents | 9046ef201591 |
children | 34ff27b431d0 |
files | Doc/library/multiprocessing.rst Lib/concurrent/futures/process.py Lib/multiprocessing/pool.py Lib/test/regrtest.py |
diffstat | 4 files changed, 7 insertions(+), 13 deletions(-)[+] [-] Doc/library/multiprocessing.rst 2 Lib/concurrent/futures/process.py 2 Lib/multiprocessing/pool.py 8 Lib/test/regrtest.py 8 |
line wrap: on
line diff
--- 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:os.cpu_count
is used. If initializer is notNone
then each worker process will callinitializer(*initargs)
when it starts.
--- 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()[](#l2.7)
self._max_workers = os.cpu_count() or 1[](#l2.8) else:[](#l2.9) self._max_workers = max_workers[](#l2.10)
--- 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:[](#l3.20)
processes = cpu_count()[](#l3.21)
except NotImplementedError:[](#l3.22)
processes = 1[](#l3.23)
processes = os.cpu_count() or 1[](#l3.24) if processes < 1:[](#l3.25) raise ValueError("Number of processes must be at least 1")[](#l3.26)
--- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -508,12 +508,8 @@ def main(tests=None, testdir=None, verbo elif o in ('-j', '--multiprocess'): use_mp = int(a) if use_mp <= 0:
try:[](#l4.7)
import multiprocessing[](#l4.8)
# Use all cores + extras for tests that like to sleep[](#l4.9)
use_mp = 2 + multiprocessing.cpu_count()[](#l4.10)
except (ImportError, NotImplementedError):[](#l4.11)
use_mp = 3[](#l4.12)
# Use all cores + extras for tests that like to sleep[](#l4.13)
use_mp = 2 + (os.cpu_count() or 1)[](#l4.14) if use_mp == 1:[](#l4.15) use_mp = None[](#l4.16) elif o == '--header':[](#l4.17)