diff options
-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: |