# HG changeset patch # User Gregory Szorc # Date 2015-05-25 20:10:38 # Node ID d29859cfcfc26c0a22b347dbbffe4308944135f3 # Parent 7154a4a08b9659006db4f1ef4e39bbe828378d11 worker: use multiprocessing to find cpu count The multiprocessing package was added in Python 2.6. The implementation of worker.countcpus() is very similar to multiprocessing.cpu_count(). Ditch our one-off code. multiprocessing does result in a number of imports. However, the lazy importer ensures that we don't import anything until cpu_count() is called. Furthermore, if we are doing something with multiple cores, chances are the time of that operation will dwarf the import time, so module bloat isn't a concern here. diff --git a/mercurial/worker.py b/mercurial/worker.py --- a/mercurial/worker.py +++ b/mercurial/worker.py @@ -8,6 +8,7 @@ from __future__ import absolute_import import errno +import multiprocessing import os import signal import sys @@ -18,24 +19,10 @@ from . import util def countcpus(): '''try to count the number of CPUs on the system''' - - # posix try: - n = int(os.sysconf('SC_NPROCESSORS_ONLN')) - if n > 0: - return n - except (AttributeError, ValueError): - pass - - # windows - try: - n = int(os.environ['NUMBER_OF_PROCESSORS']) - if n > 0: - return n - except (KeyError, ValueError): - pass - - return 1 + return multiprocessing.cpu_count() + except NotImplementedError: + return 1 def _numworkers(ui): s = ui.config('worker', 'numcpus')