mlco2 / codecarbon

Track emissions from Compute and recommend ways to reduce their impact on the environment.
https://mlco2.github.io/codecarbon
MIT License
1.01k stars 158 forks source link

stop_task PeP8 in emission_tracker is probably incorrect #446

Closed VictorCrd closed 9 months ago

VictorCrd commented 10 months ago

Description

PeP8 definition of stop_task might need to be changed.

Function is currently returning task_emission_data (EmissionsData).

But PeP8 info is "the function is returning None / a float"

Correct PeP8 might be this:

def stop_task(self, task_name: str = None) ->  EmissionsData:
    """
    Stop tracking a dedicated execution task. Delta energy is computed by task, to isolate its contribution to total
    emissions.
    :return: EmissionsData
    """
    task_name = task_name if task_name else self._active_task
    self._measure_power_and_energy()

    emissions_data = self._prepare_emissions_data(delta=True)

    task_duration = Time.from_seconds(
        time.time() - self._tasks[task_name].start_time
    )

    task_emission_data = emissions_data
    task_emission_data.duration = task_duration.seconds
    self._tasks[task_name].emissions_data = task_emission_data
    self._tasks[task_name].is_active = False
    self._active_task = None
    return task_emission_data
inimaz commented 9 months ago

This has been solved by #452