Skip to content

Commit 9d6c4d5

Browse files
committed
Check scheduler exists before checking if it has stopped - a cause of test flakiness
1 parent 73a1d6b commit 9d6c4d5

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

codecarbon/emissions_tracker.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,11 @@ def _measure_power_and_energy(self) -> None:
851851
raise e
852852

853853
warning_duration = self._measure_power_secs * 3
854-
if last_duration > warning_duration and not self._scheduler._stopped:
854+
if (
855+
last_duration > warning_duration
856+
and self._scheduler
857+
and not self._scheduler._stopped
858+
):
855859
warn_msg = (
856860
"Background scheduler didn't run for a long period"
857861
+ " (%ds), results might be inaccurate"

0 commit comments

Comments
 (0)