← Back to issue list

project: add fallbacks for os.sched_getaffinity

View original Github issue

Metadata

Project
snapcraft
Number
#2963
Type
pull request
State
merged
Author
cjp256
Labels
—
Created
Updated
Closed

Current evaluation

Merged #2963 (commit fc9799b26): get_parallel_build_count now falls back to multiprocessing.cpu_count(), then 1, when os.sched_getaffinity() is missing (e.g. macOS), fixing the regression from 332df0f9; unit tests added.

Resolution: closed resolved

Reason: The PR was approved and merged as commit fc9799b26 ('project: add fallbacks for os.sched_getaffinity (#2963)'), which introduced an AttributeError fallback chain (os.sched_getaffinity -> multiprocessing.cpu_count -> 1) in the CPU-count helper, plus tests in tests/unit/test_utils.py that patch os.sched_getaffinity with side_effect=AttributeError.

Evaluated by: mr-cal-bot

No scores available.

Issue body

Project was recently updated [1] to use os.sched_getaffinity() to get a more accurate view of how many threads are available for use. However, OSX does not implement os.sched_getaffinity(), failing with AttributeError. Fall back to multiprocessing.cpu_count if os.sched_getaffinity() does not exist. Failing that, return 1. Add a couple of unit tests for coverage. [1] 332df0f97e93ac7ecc325f929faacb79ae55ddd1 Signed-off-by: Chris Patterson <chris.patterson@canonical.com> - [ ] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)? - [ ] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)? - [ ] Have you successfully run `./runtests.sh static`? - [ ] Have you successfully run `./runtests.sh tests/unit`? -----

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed resolved Merged #2963 (commit fc9799b26): get_parallel_build_count now falls back to multiprocessing.cpu_count(), then 1, when os.sched_getaffinity() is missing (e.g. macOS), fixing the regression from 332df0f9; unit tests added.
stealth/space-bunny-alpha — closed resolved Merged #2963 (fc9799b26), adding multiprocessing.cpu_count and then 1 as fallbacks when os.sched_getaffinity is unavailable, plus unit tests.
qwen/qwen3.6-35b-a3b — — Merged changes adding fallback logic for os.sched_getaffinity to resolve macOS AttributeError. The update falls back to multiprocessing.cpu_count or returns 1, includes unit tests, and passed CI review.
qwen3.6-35b-a3b-mtp-q6 — — Merged. Added fallback logic for os.sched_getaffinity to resolve macOS AttributeError, defaulting to multiprocessing.cpu_count or 1. Includes unit tests.

Update history

No update history recorded yet.

Related issues

Issue Project State Summary Similarity
#2732 project: use os.sched_getaffinity instead of multiprocessing.cpu_count snapcraft merged Merged as commit 332df0f97 (approved by 2 reviewers, +4/-11 across 3 files), replacing multiprocessing.cpu_count() with os.sched_getaffinity() in project code so parallel build counts honour cgroup/affinity limits such as LXD containers.
80%