mirror of
https://github.com/facebook/sapling.git
synced 2024-10-08 07:49:11 +03:00
worker: count the number of CPUs
This works on the major platforms, and falls back to a safe guess of 1 elsewhere.
This commit is contained in:
parent
2429ebf0ed
commit
46bf2f5a6f
29
mercurial/worker.py
Normal file
29
mercurial/worker.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# worker.py - master-slave parallelism support
|
||||||
|
#
|
||||||
|
# Copyright 2013 Facebook, Inc.
|
||||||
|
#
|
||||||
|
# This software may be used and distributed according to the terms of the
|
||||||
|
# GNU General Public License version 2 or any later version.
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
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
|
Loading…
Reference in New Issue
Block a user