MCPcopy Create free account
hub / github.com/mlco2/codecarbon / _create_warn_function

Function _create_warn_function

codecarbon/core/cpu.py:161–183  ·  view source on GitHub ↗

Create a warning function that only warns once for permission errors.

()

Source from the content-addressed store, hash-verified

159
160
161def _create_warn_function():
162 """Create a warning function that only warns once for permission errors."""
163 already_warned = False
164
165 def warn_permission_denied(energy_path: str):
166 nonlocal already_warned
167 if not already_warned:
168 logger.warning(
169 "\tRAPL - Permission denied reading RAPL file %s. "
170 "You can grant read permission with: "
171 "sudo chmod -R a+r /sys/class/powercap/*",
172 energy_path,
173 )
174 already_warned = True
175 else:
176 logger.debug(
177 "\tRAPL - Permission denied reading RAPL file %s. "
178 "You can grant read permission with: "
179 "sudo chmod -R a+r /sys/class/powercap/*",
180 energy_path,
181 )
182
183 return warn_permission_denied
184
185
186def is_rapl_available(rapl_dir: Optional[str] = None) -> bool:

Callers 1

is_rapl_availableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…