mlco2 / codecarbon

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

Codecarbon keep running even when function fails #409

Closed abhishekkrthakur closed 1 year ago

abhishekkrthakur commented 1 year ago

As the title says. The function crashes but codecarbon keeps running. this is quite undesirable if codecarbon has to be used in a production environment. For example, a training ran for 3 days just because code carbon didnt shut down after function crash. Is it possible to fix it soon?

benoit-cty commented 1 year ago

Hello, Can you share the way you call it ? If you use the decorator it should work. If you use tracker.start(), you have to do a tracker.stop() in the try/except.

abhishekkrthakur commented 1 year ago

yeah. not using decorator.

benoit-cty commented 1 year ago

The problem is that we use a scheduler and I don't know how to let it know that the main program has crashed without using the decorator. We need to had this in the documentation.

try:
    # Compute intensive code goes here
    a = 1 + 1
finally:
    emissions = tracker.stop()
print(f"{emissions} kgCO2eq")