Skip to content
Snippets Groups Projects
Commit c0501c26 authored by Gregory Szorc's avatar Gregory Szorc
Browse files

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.
parent f18646cf
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,6 @@
from __future__ import absolute_import
import errno
import multiprocessing
import os
import signal
import sys
......@@ -19,4 +18,6 @@
def countcpus():
'''try to count the number of CPUs on the system'''
# posix
try:
......@@ -22,7 +23,19 @@
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')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment