diff options
author | Chandan Singh <chandan@chandansingh.net> | 2020-01-02 11:32:58 +0000 |
---|---|---|
committer | Chandan Singh <chandan@chandansingh.net> | 2020-01-02 11:32:58 +0000 |
commit | 8961e2755d613b4bb97e1d3d37ccda3260f0faa7 (patch) | |
tree | fddca2ae598db759f046954c27bcc9799da53e27 | |
parent | c8153bc7b7e9fd989ae2a6be3e2dea8aedad0343 (diff) | |
parent | 51f72e9f30c0edf855471ae052bcde62394bc09b (diff) | |
download | buildstream-8961e2755d613b4bb97e1d3d37ccda3260f0faa7.tar.gz |
Merge branch 'chandan/fix-cpu-count' into 'master'
_platform: Don't use psutil.Process.cpu_affinity on unsupported platforms
Closes #1244
See merge request BuildStream/buildstream!1786
-rw-r--r-- | src/buildstream/_platform/darwin.py | 8 | ||||
-rw-r--r-- | src/buildstream/_platform/platform.py | 10 |
2 files changed, 9 insertions, 9 deletions
diff --git a/src/buildstream/_platform/darwin.py b/src/buildstream/_platform/darwin.py index 06491e8b4..2e244557e 100644 --- a/src/buildstream/_platform/darwin.py +++ b/src/buildstream/_platform/darwin.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU Lesser General Public # License along with this library. If not, see <http://www.gnu.org/licenses/>. -import os import resource from ..sandbox import SandboxDummy @@ -28,13 +27,6 @@ class Darwin(Platform): # This value comes from OPEN_MAX in syslimits.h OPEN_MAX = 10240 - def get_cpu_count(self, cap=None): - cpu_count = os.cpu_count() - if cap is None: - return cpu_count - else: - return min(cpu_count, cap) - def maximize_open_file_limit(self): # Note that on Mac OSX, you may not be able to simply set the soft # limit to the reported hard limit, as it may not be the only limit in diff --git a/src/buildstream/_platform/platform.py b/src/buildstream/_platform/platform.py index b58ae3e3d..c838ef6c2 100644 --- a/src/buildstream/_platform/platform.py +++ b/src/buildstream/_platform/platform.py @@ -122,7 +122,15 @@ class Platform: return PlatformImpl(force_sandbox=force_sandbox) def get_cpu_count(self, cap=None): - cpu_count = len(psutil.Process().cpu_affinity()) + # `psutil.Process.cpu_affinity()` is not available on all platforms. + # So, fallback to getting the total cpu count in cases where it is not + # available. + dummy_process = psutil.Process() + if hasattr(dummy_process, "cpu_affinity"): + cpu_count = len(dummy_process.cpu_affinity()) + else: + cpu_count = os.cpu_count() + if cap is None: return cpu_count else: |