Skip to content

Fix issues for Windows hosts#1054

Merged
benoit-cty merged 6 commits intomlco2:masterfrom
arno-hc:experiment
Feb 8, 2026
Merged

Fix issues for Windows hosts#1054
benoit-cty merged 6 commits intomlco2:masterfrom
arno-hc:experiment

Conversation

@arno-hc
Copy link

@arno-hc arno-hc commented Feb 6, 2026

Description

For Windows hosts function is_psutils_available() fails.

utils function get_physical_cpu_count() delivers not the number of sockets, but the number of logical cores.

Related Issue

n.a.

Motivation and Context

On Windows host the energy consumption did fall back to a constant estimation (not taking CPU load into account). The reason for this is the is_psutils_available() function not working on Windows, although psutils is functioning on Windows.

The number of physical CPU problem showed up after solving is_psutils_available(). The reported numbers were not plausible.

How Has This Been Tested?

Unit tests are added. Before that manual tests on Windows host was performed.

Screenshots (if appropriate):

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • [ x] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

  • [ x] My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • [x ] I have read the CONTRIBUTING.md document.
  • [x ] I have added tests to cover my changes.
  • [ x] All new and existing tests passed. --> one test seems to be flaky: test_emissions_tracker_constant.py::TestCarbonTrackerConstant::test_carbon_tracker_offline_load_force_cpu_power

@arno-hc arno-hc requested a review from a team as a code owner February 6, 2026 16:13
Copy link
Contributor

@benoit-cty benoit-cty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much !
We plan to improve Windows support next month, that's a great help.

@codecov
Copy link

codecov bot commented Feb 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.51%. Comparing base (2d52a20) to head (abcaf04).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1054      +/-   ##
==========================================
+ Coverage   68.26%   68.51%   +0.25%     
==========================================
  Files          41       41              
  Lines        3847     3862      +15     
==========================================
+ Hits         2626     2646      +20     
+ Misses       1221     1216       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

@benoit-cty
Copy link
Contributor

To manually test on Windows:

  1. Run: python -c "from codecarbon.core.cpu import is_psutil_available; print(is_psutil_available())"
  2. Run: python -c "from codecarbon.core.util import count_physical_cpus; print(count_physical_cpus())"
  3. Compare socket count with: Get-CimInstance -ClassName Win32_Processor | Measure-Object

- Add test for is_psutil_available() with small nice value
- Add comprehensive error handling tests for count_physical_cpus() on Windows:
  - CalledProcessError
  - TimeoutExpired
  - ValueError for invalid output

This brings test coverage to 100% for the Windows-specific code paths added in the PR.
@benoit-cty benoit-cty merged commit 3242f27 into mlco2:master Feb 8, 2026
10 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.

2 participants