Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 4, 2024
Merged

Conversation

inimaz
Copy link
Contributor

@inimaz inimaz commented Nov 1, 2024

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:

  • the user does Ctl + C to terminate the script
  • there is a python error in between start and stop
  • Some other error terminates it

@inimaz inimaz added the bug Something isn't working label Nov 1, 2024
Signed-off-by: inimaz <93inigo93@gmail.com>
Copy link
Contributor

@benoit-cty benoit-cty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulation for finding a solution !
atexit and signal are included Python library so no need to create new dependencies, nice.

@inimaz inimaz merged commit 6391b66 into master Nov 4, 2024
13 checks passed
@inimaz inimaz deleted the fix/lock-release branch November 4, 2024 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants