Skip to content

fix: handle psutil errors gracefully in _get_ncpus#267

Merged
AlexanderFengler merged 1 commit intomainfrom
bug-fix-toward-0.12.1
Mar 18, 2026
Merged

fix: handle psutil errors gracefully in _get_ncpus#267
AlexanderFengler merged 1 commit intomainfrom
bug-fix-toward-0.12.1

Conversation

@AlexanderFengler
Copy link
Member

@AlexanderFengler AlexanderFengler commented Mar 17, 2026

Summary

  • Catches Exception around psutil.cpu_count to prevent SystemError on restricted environments (e.g. macOS sandbox, some CI runners)
  • Implements an affinity-aware hierarchy (os.sched_getaffinity -> os.process_cpu_count -> os.cpu_count -> psutil) to prevent massive oversubscription on HPC clusters and SLURM allocations where the OS limits the cores available to the python process.
  • If all cpu detection fails, raises a RuntimeError instead of silently falling back to 1 core, preventing unintended very slow simulations
  • Adds a logger.info log message outputting the resolved number of cores so users can easily verify their config
  • Adds a test verifying the new robust fallback behavior

@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 91.49% <100.00%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
ssms/dataset_generators/lan_mlp.py 93.57% <100.00%> (+1.70%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AlexanderFengler AlexanderFengler force-pushed the bug-fix-toward-0.12.1 branch 2 times, most recently from a99df4c to 3cbfe38 Compare March 17, 2026 23:08
- Robust CPU detection cascade: sched_getaffinity → cpu_count → psutil
- Explicit RuntimeError if all detection methods fail
- Always log resolved core count for HPC verification
- pragma: no cover on platform-specific unreachable branches

Made-with: Cursor
@AlexanderFengler AlexanderFengler merged commit 0928b94 into main Mar 18, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant