Fix: Disable scheduler warning when scheduler is stopped#926
Conversation
- Add condition to check if we're in task mode (self._active_task is not None) - Skip scheduler warning when in task mode since scheduler is intentionally stopped - Preserves warning functionality in normal mode when there are actual delays - Tested with task mode examples and integration tests Co-authored-by: benoit-cty <6603048+benoit-cty@users.noreply.github.com>
|
@copilot I think it's better to use And can you add a test to verify the expected behavior ? |
…dd tests - Replace `self._active_task is None` with `not self._scheduler._stopped` in warning condition - Add comprehensive tests to verify warning behavior when scheduler is stopped vs running - Tests confirm warning is suppressed when scheduler is intentionally stopped (e.g., in task mode) - Tests confirm warning still appears when scheduler should be running but is delayed Co-authored-by: benoit-cty <6603048+benoit-cty@users.noreply.github.com>
Good suggestion! I've updated the implementation to use I've also added comprehensive tests as requested:
The tests confirm the expected behavior in both scenarios and handle multiple warning types correctly. Changes are in commit eb655b2. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
SaboniAmine
left a comment
There was a problem hiding this comment.
LGTM, thanks Benoît for handling this case!
The background scheduler warning was incorrectly appearing when the scheduler was intentionally stopped, such as during task mode execution.
Problem
When using CodeCarbon's task mode (e.g.,
tracker.start_task()/tracker.stop_task()) or when the scheduler is manually stopped, users would see inappropriate warnings like:This occurred because:
_measure_power_and_energy()method is called manually duringstop_task()Solution
Modified the warning condition in
_measure_power_and_energy()to check if the scheduler is currently stopped (not self._scheduler._stopped) and skip the warning in that context.Before:
After:
Testing
This change preserves the warning's utility in normal mode while eliminating the false positives when the scheduler is intentionally stopped for any reason, not just task mode.
Fixes #925.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.