Imagine I open 2 clis and run codecarbon monitor in each of them. This will result on both of them outputing very similar data to the same output. Now imagine I have multiple instances of codecarbon (e.g. a python script, some cli, some script somewhere that I forgot it is running...). This could become complex rapidly.
Goal of this PR
By default it will allow only one instance per machine to measure at the same time.
This is regulated via the parameter allow_multiple_runs.
If true --> multiple runs of codecarbon can be done in the same machine.
If false --> only one at the same time.
Default is false.
How to test this
Option 1: using 2 consoles
Open 2 consoles and run hatch run python examples/logging_to_file.py on both of them.
Output of Console 1: Normal behavior
Output of Console 2:
[codecarbon ERROR @ 18:17:11] Error: Another instance of codecarbon is already running. Turn off the other instance to be able to run this one. Exiting.
Option 2: multiprocess
I have added an example of exclusive run using multiprocess.
Run it via hatch run python examples/logging_to_file_exclusive_run.py
Example of output:
~/codecarbon$ hatch run python examples/logging_to_file_exclusive_run.py
[codecarbon INFO @ 09:43:43] offline tracker init
[codecarbon INFO @ 09:43:43] offline tracker init
[codecarbon INFO @ 09:43:43] offline tracker init
[codecarbon INFO @ 09:43:43] offline tracker init
[codecarbon ERROR @ 09:43:43] Error: Another instance of codecarbon is already running. Turn off the other instance to be able to run this one. Exiting.
[codecarbon ERROR @ 09:43:43] Error: Another instance of codecarbon is already running. Turn off the other instance to be able to run this one. Exiting.
[codecarbon ERROR @ 09:43:43] Error: Another instance of codecarbon is already running. Turn off the other instance to be able to run this one. Exiting.
[codecarbon INFO @ 09:43:43] offline tracker init
[codecarbon ERROR @ 09:43:43] Error: Another instance of codecarbon is already running. Turn off the other instance to be able to run this one. Exiting.
[codecarbon INFO @ 09:43:43] [setup] RAM Tracking...
[codecarbon INFO @ 09:43:43] [setup] GPU Tracking...
...
We see that 5 instances of codecarbon are started and 4 end up in error and exit.
Imagine I open 2 clis and run
codecarbon monitor
in each of them. This will result on both of them outputing very similar data to the same output. Now imagine I have multiple instances of codecarbon (e.g. a python script, some cli, some script somewhere that I forgot it is running...). This could become complex rapidly.Goal of this PR
By default it will allow only one instance per machine to measure at the same time. This is regulated via the parameter
allow_multiple_runs
.Default is
false
.How to test this
Option 1: using 2 consoles
Open 2 consoles and run
hatch run python examples/logging_to_file.py
on both of them.Option 2: multiprocess
I have added an example of exclusive run using multiprocess. Run it via
hatch run python examples/logging_to_file_exclusive_run.py
Example of output:We see that 5 instances of
codecarbon
are started and 4 end up in error and exit.