summaryrefslogtreecommitdiff
path: root/buildstream
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2018-10-01 10:18:05 +0200
committerJürg Billeter <j@bitron.ch>2018-10-01 10:18:05 +0200
commit14e1a3b3394ff0517ae7f4a287de33cf52a654d6 (patch)
treecd50472137c7b9c0629375d46a1271424af5562e /buildstream
parent5d3f039f0d2067f14c1d746d7d00ad859b1c4737 (diff)
downloadbuildstream-14e1a3b3394ff0517ae7f4a287de33cf52a654d6.tar.gz
_platform: Fix get_cpu_count() with cap=None
Comparison between None and integer is not supported.
Diffstat (limited to 'buildstream')
-rw-r--r--buildstream/_platform/darwin.py7
-rw-r--r--buildstream/_platform/platform.py6
2 files changed, 9 insertions, 4 deletions
diff --git a/buildstream/_platform/darwin.py b/buildstream/_platform/darwin.py
index 7092eb2aa..c4361e897 100644
--- a/buildstream/_platform/darwin.py
+++ b/buildstream/_platform/darwin.py
@@ -41,10 +41,11 @@ class Darwin(Platform):
return True
def get_cpu_count(self, cap=None):
- if cap < os.cpu_count():
- return cap
+ cpu_count = os.cpu_count()
+ if cap is None:
+ return cpu_count
else:
- return os.cpu_count()
+ return min(cpu_count, cap)
def set_resource_limits(self, soft_limit=OPEN_MAX, hard_limit=None):
super().set_resource_limits(soft_limit)
diff --git a/buildstream/_platform/platform.py b/buildstream/_platform/platform.py
index bc6a624c4..d3e4b949a 100644
--- a/buildstream/_platform/platform.py
+++ b/buildstream/_platform/platform.py
@@ -67,7 +67,11 @@ class Platform():
return cls._instance
def get_cpu_count(self, cap=None):
- return min(len(os.sched_getaffinity(0)), cap)
+ cpu_count = len(os.sched_getaffinity(0))
+ if cap is None:
+ return cpu_count
+ else:
+ return min(cpu_count, cap)
##################################################################
# Sandbox functions #