Skip to content

Commit f969378

Browse files
author
root
committed
Added more static types
Corrected usage of int compared to [int]
1 parent 6511b93 commit f969378

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

codecarbon/emissions_tracker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __init__(
176176
str
177177
] = _sentinel, # Deprecated, use electricitymaps_api_token
178178
tracking_mode: Optional[str] = _sentinel,
179-
tracking_pids: Optional[int] = _sentinel,
179+
tracking_pids: Optional[List[int]] = _sentinel,
180180
log_level: Optional[Union[int, str]] = _sentinel,
181181
on_csv_write: Optional[str] = _sentinel,
182182
logger_preamble: Optional[str] = _sentinel,
@@ -1182,7 +1182,7 @@ def track_emissions(
11821182
str
11831183
] = _sentinel, # Deprecated, use electricitymaps_api_token
11841184
tracking_mode: Optional[str] = _sentinel,
1185-
tracking_pids: Optional[int] = _sentinel,
1185+
tracking_pids: Optional[List[int]] = _sentinel,
11861186
log_level: Optional[Union[int, str]] = _sentinel,
11871187
on_csv_write: Optional[str] = _sentinel,
11881188
logger_preamble: Optional[str] = _sentinel,

codecarbon/external/ram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(
5050
total RAM used. Defaults to True.
5151
tracking_mode (str, optional): Whether to track "machine" or "process" RAM.
5252
Defaults to "machine".
53-
tracking_pids (int, optional): Process id to track RAM usage for "process"
53+
tracking_pids ([int], optional): Process id to track RAM usage for "process"
5454
tracking_mode. Defaults to None.
5555
force_ram_power (int, optional): User-provided RAM power in watts. If provided,
5656
this value is used instead of estimating RAM power.

tests/test_pid_tracking.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_carbon_pid_tracking_offline(self):
5757
output_dir=self.emissions_path,
5858
output_file=self.emissions_file + "_global.csv",
5959
tracking_mode="process",
60-
tracking_pids=os.getpid(),
60+
tracking_pids=[os.getpid()],
6161
)
6262

6363
tracker_pid.start()
@@ -76,4 +76,10 @@ def test_carbon_pid_tracking_offline(self):
7676
assert isinstance(emissions_pid, float)
7777

7878
self.assertNotEqual(emissions_pid, 0.0)
79-
self.assertAlmostEqual(emissions_self, emissions_pid, 2)
79+
80+
# Compare emissions from both trackers, should be less than 10% difference
81+
diff = abs(emissions_pid - emissions_self)
82+
avg = (emissions_pid + emissions_self) / 2
83+
percent_diff = (diff / avg) * 100
84+
print(f"Percent difference: {percent_diff}%")
85+
self.assertLessEqual(percent_diff, 10.0)

0 commit comments

Comments
 (0)