From 230fb77b5ed911401ea37131c5c1f5c787804d77 Mon Sep 17 00:00:00 2001 From: Qiyun Zhu Date: Thu, 21 Sep 2023 12:14:37 -0700 Subject: [PATCH] using MacOS-compatible CPU count --- hgtector/search.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hgtector/search.py b/hgtector/search.py index 8c63f28..eec1f35 100644 --- a/hgtector/search.py +++ b/hgtector/search.py @@ -8,8 +8,9 @@ # The full license is in the file LICENSE, distributed with this software. # ---------------------------------------------------------------------------- +import os import re -from os import remove, makedirs, sched_getaffinity +from os import remove, makedirs from os.path import join, isdir, isfile from shutil import which, rmtree from tempfile import mkdtemp @@ -131,8 +132,13 @@ def __call__(self, args): # read and validate input data self.input_wf() + # check available threads + try: + m = len(os.sched_getaffinity(0)) + except AttributeError: + m = os.cpu_count() + # check requested threads if set vs available ones - m = len(sched_getaffinity(0)) if self.threads and self.threads > m: print( f'WARNING: Threads limited to {m} (requested {self.threads}).')