Skip to content

Commit 10c656f

Browse files
committed
Replaced unavailable os.sched_getaffinity call on macOS
os.sched_getaffinity does not exist on macOS and a similar workaround is already used in src/fairseq2/recipes/utils/log.py
1 parent cffa520 commit 10c656f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/fairseq2/utils/threading.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ def get_num_threads(env: Mapping[str, str]) -> int:
8181
def _get_num_cpus(num_procs: int) -> int:
8282
num_cpus = os.cpu_count()
8383

84-
affinity_mask = os.sched_getaffinity(0)
84+
try:
85+
affinity_mask = os.sched_getaffinity(0)
86+
except AttributeError: # Python on macOS does not have `sched_getaffinity`.
87+
if num_cpus is None:
88+
affinity_mask = None
89+
else:
90+
affinity_mask = set(range(num_cpus))
8591

8692
if num_cpus is None or affinity_mask is None:
8793
raise ThreadingError(

0 commit comments

Comments
 (0)