Mercurial > hg-stable
changeset 26568:c0501c26b05c
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.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 08 Oct 2015 10:57:03 -0700 |
parents | f18646cf0e93 |
children | 2aeeef1dc9a5 |
files | mercurial/worker.py |
diffstat | 1 files changed, 17 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/worker.py Wed Oct 07 21:22:16 2015 -0700 +++ b/mercurial/worker.py Thu Oct 08 10:57:03 2015 -0700 @@ -8,7 +8,6 @@ from __future__ import absolute_import import errno -import multiprocessing import os import signal import sys @@ -19,10 +18,24 @@ 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')