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

Allow MacOS sudo to be bypassed #736

Open
ElliottKasoar opened this issue Dec 11, 2024 · 0 comments
Open

Allow MacOS sudo to be bypassed #736

ElliottKasoar opened this issue Dec 11, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@ElliottKasoar
Copy link

ElliottKasoar commented Dec 11, 2024

  • CodeCarbon version: 2.8.1
  • Python version: 3.12.8
  • Operating System: MacOS 15.1

Description

Currently, when sudo is available on MacOS, I believe it is unavoidable that powermetrics.is_powermetrics_available() will attempt to use it, even if a default power is supplied.

Although ways to avoid the need for sudo entirely would be significantly more useful (e.g. discussion in #731), a simple short term solution could be to swap the current check:

powermetrics.is_powermetrics_available() and self._default_cpu_power is None

If instead the check against _default_cpu_power is performed first, this would enable avoiding the need to call powermetrics.is_powermetrics_available().

It may also be more efficient to swap this check for other branches of if statements, although I haven't encountered specific issues. (There's also cpu.is_rapl_available(), which doesn't check whether self._default_cpu_power is None. This seems inconsistent, but it may be intentional?)

What I Did

from codecarbon import OfflineEmissionsTracker
from codecarbon.external.hardware import POWER_CONSTANT

OfflineEmissionsTracker(
    country_iso_code="GBR",
    default_cpu_power=POWER_CONSTANT,
    log_level="DEBUG",
)

This currently prompts for a password, even when the supplied default will be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants