Skip to content

Commit 9db53a2

Browse files
authored
fix(cli): codecarbon monitor --no-api working again (#721)
1 parent 6973ed9 commit 9db53a2

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

codecarbon/cli/main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,17 @@ def monitor(
316316
api (Annotated[bool, typer.Option, optional): Choose to call Code Carbon API or not. Defaults to True.
317317
"""
318318
experiment_id = get_existing_local_exp_id()
319-
if api and experiment_id is None:
320-
print("ERROR: No experiment id, call 'codecarbon init' first.", err=True)
319+
token = None
320+
if api:
321+
if experiment_id is None:
322+
print("ERROR: No experiment id, call 'codecarbon init' first.", err=True)
323+
token = _get_access_token()
321324
print("CodeCarbon is going in an infinite loop to monitor this machine.")
322325
with EmissionsTracker(
323326
measure_power_secs=measure_power_secs,
324327
api_call_interval=api_call_interval,
325328
save_to_api=api,
326-
access_token=_get_access_token(),
329+
access_token=token,
327330
) as tracker:
328331
# Infinite loop
329332
while True:

0 commit comments

Comments
 (0)