mlco2 / codecarbon

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

fix: lock release when there is a python error #701

Closed inimaz closed 3 weeks ago

inimaz commented 3 weeks ago

Before

If there was an error in the user's code

tracker.start()

raise ValueError()

tracker.stop() <== this line is never called

the lock will not be removed. Meaning the next time you run the same script, you will get an error Error: Another instance of codecarbon is already running. Turn off the other instance to be able to run this one. Exiting.

Now

The lock is removed even if: