# HG changeset patch # User Gregory Szorc # Date 2015-10-08 17:57:03 # Node ID c0501c26b05c6f50b8638753306dfc13144fe5d6 # Parent f18646cf0e936287237160f33289f065cf02eb7b worker: restore old countcpus code (issue4869) This is a backout of d29859cfcfc2. The stdlib implementation of multiprocessing.cpu_count() attempts to invoke a process on BSD and Darwin platforms (at least on 2.7). Under certain conditions (such as cwd being removed) this could raise. Our old code was silently catching the exception. The old code was more robust, so restore it. diff --git a/mercurial/worker.py b/mercurial/worker.py --- a/mercurial/worker.py +++ b/mercurial/worker.py @@ -8,7 +8,6 @@ from __future__ import absolute_import import errno -import multiprocessing import os import signal import sys @@ -19,10 +18,24 @@ from . import util def countcpus(): '''try to count the number of CPUs on the system''' + + # posix try: - return multiprocessing.cpu_count() - except NotImplementedError: - return 1 + 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 def _numworkers(ui): s = ui.config('worker', 'numcpus')