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

Method __post_init__

codecarbon/core/rapl.py:24–45  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

22 max_energy_reading: Energy = field(default_factory=lambda: Energy(0))
23
24 def __post_init__(self):
25 self.last_energy = self._get_value()
26 try:
27 with open(self.max_path, "r") as f:
28 max_micro_joules = float(f.read())
29 self.max_energy_reading = Energy.from_ujoules(max_micro_joules)
30 except Exception as e:
31 # If we cannot read the max range, log and set to 0 so wrap detection
32 # will be effectively disabled for this file.
33 if isinstance(e, PermissionError):
34 logger.warning(
35 "Unable to read max_energy_range_uj from %s due to permission error: %s",
36 self.max_path,
37 e,
38 )
39 else:
40 logger.debug(
41 "Unable to read max_energy_range_uj from %s: %s",
42 self.max_path,
43 e,
44 )
45 self.max_energy_reading = Energy.from_ujoules(0)
46
47 def _get_value(self) -> Energy:
48 """

Callers

nothing calls this directly

Calls 2

_get_valueMethod · 0.95
from_ujoulesMethod · 0.80

Tested by

no test coverage detected