Mercurial > hg
changeset 26063:d29859cfcfc2
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.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 25 May 2015 13:10:38 -0700 |
parents | 7154a4a08b96 |
children | 1b1ab6ff58c4 |
files | mercurial/worker.py |
diffstat | 1 files changed, 4 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/worker.py Mon Aug 24 10:09:00 2015 -0400 +++ b/mercurial/worker.py Mon May 25 13:10:38 2015 -0700 @@ -8,6 +8,7 @@ from __future__ import absolute_import import errno +import multiprocessing import os import signal import sys @@ -18,24 +19,10 @@ 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')