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

Raise an exception when another is running #713

Closed
wants to merge 1 commit into from

Conversation

benoit-cty
Copy link
Contributor

Problem

Currently, when running codecarbon monitor while another instance is active, the CLI displays "Another instance of codecarbon is already running" but continues its infinite loop instead of terminating. This creates a confusing user experience.

Solution

Modify the behavior to raise an exception when detecting another running instance, forcing the program to terminate unless the calling code explicitly handles this case.
This makes the error condition more explicit and helps prevent unintended parallel executions of codecarbon monitoring.
Please review and provide feedback on this approach.

@benoit-cty
Copy link
Contributor Author

After a discussion, we prefer to keep this behavior : let the user know in log that CodeCarbon will not work and do not stop his process.

Here is an code sample if a user want to know about CodeCarbon not doing the measure:

  with EmissionsTracker() as tracker:
       # Infinite loop
       while True:
           if (
               hasattr(tracker, "_another_instance_already_running")
               and tracker._another_instance_already_running
           ):
               print("Another instance of CodeCarbon is already running. Exiting.")
               break
           # The compute code goes here
           time.sleep(300)

@benoit-cty benoit-cty closed this Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant