comparison mercurial/worker.py @ 18635:fed06dd07665

worker: count the number of CPUs This works on the major platforms, and falls back to a safe guess of 1 elsewhere.
author Bryan O'Sullivan <bryano@fb.com>
date Sat, 09 Feb 2013 15:22:12 -0800
parents
children dcb27c153a40
comparison
equal deleted inserted replaced
18634:4b5d37ca3c11 18635:fed06dd07665
1 # worker.py - master-slave parallelism support
2 #
3 # Copyright 2013 Facebook, Inc.
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
7
8 import os
9
10 def countcpus():
11 '''try to count the number of CPUs on the system'''
12
13 # posix
14 try:
15 n = int(os.sysconf('SC_NPROCESSORS_ONLN'))
16 if n > 0:
17 return n
18 except (AttributeError, ValueError):
19 pass
20
21 # windows
22 try:
23 n = int(os.environ['NUMBER_OF_PROCESSORS'])
24 if n > 0:
25 return n
26 except (KeyError, ValueError):
27 pass
28
29 return 1