diff --git a/src/inifix/_cli.py b/src/inifix/_cli.py index 589b467..7fd7773 100644 --- a/src/inifix/_cli.py +++ b/src/inifix/_cli.py @@ -1,6 +1,7 @@ from __future__ import annotations import os +import sys from typing import Literal, NamedTuple, TextIO @@ -17,4 +18,14 @@ class TaskResults(NamedTuple): def get_cpu_count() -> int: # this function exists primarily to be mocked # instead of something we don't own - return os.cpu_count() or 1 + base_cpu_count: int | None + if sys.version_info >= (3, 13): + base_cpu_count = os.process_cpu_count() + else: + if hasattr(os, "sched_getaffinity"): + # this function isn't available on all platforms + base_cpu_count = len(os.sched_getaffinity(0)) + else: + # this proxy is good enough in most situations + base_cpu_count = os.cpu_count() + return base_cpu_count or 1