Skip to content

Commit f346008

Browse files
authored
Merge pull request #786 from mlco2/fix/remove_deprecated_psutil_percpu
fix: remove percpu argument for psutil.cpu_percent & process.cpu_percent calls
2 parents 9674f05 + 63b2994 commit f346008

18 files changed

+260
-243
lines changed

codecarbon/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.0.0_rc1"
1+
__version__ = "3.0.0_rc2"

codecarbon/external/hardware.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,16 @@ def _get_power_from_cpu_load(self):
210210
"""
211211
if self._tracking_mode == "machine":
212212
tdp = self._tdp
213-
cpu_load = psutil.cpu_percent(interval=0.5, percpu=False)
213+
cpu_load = psutil.cpu_percent(interval=0.5)
214214
power = self._calculate_power_from_cpu_load(tdp, cpu_load, self._model)
215215
logger.debug(
216216
f"A TDP of {self._tdp} W and a CPU load of {cpu_load:.1f}% give an estimation of {power} W for whole machine."
217217
)
218218
elif self._tracking_mode == "process":
219-
cpu_load = (
220-
self._process.cpu_percent(interval=0.5, percpu=False) / self._cpu_count
219+
cpu_load = self._process.cpu_percent(interval=0.5) / self._cpu_count
220+
power = self._calculate_power_from_cpu_load(
221+
self._tdp, cpu_load, self._model
221222
)
222-
power = self._calculate_power_from_cpu_load(self.tdp, cpu_load, self._model)
223223
logger.debug(
224224
f"A TDP of {self._tdp} W and a CPU load of {cpu_load * 100:.1f}% give an estimation of {power} W for process {self._pid}."
225225
)

codecarbon/output_methods/file.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,26 @@ def out(self, total: EmissionsData, delta: EmissionsData):
4646
logger.info("Backing up old emission file")
4747
backup(self.save_file_path)
4848
file_exists = False
49-
49+
new_df = pd.DataFrame.from_records([dict(total.values)])
50+
new_df = new_df.dropna(axis=1, how="all")
5051
if not file_exists:
5152
df = pd.DataFrame(columns=total.values.keys())
52-
df = pd.concat([df, pd.DataFrame.from_records([dict(total.values)])])
53+
df = pd.concat([df, new_df])
5354
elif self.on_csv_write == "append":
5455
df = pd.read_csv(self.save_file_path)
55-
df = pd.concat([df, pd.DataFrame.from_records([dict(total.values)])])
56+
df = pd.concat([df, new_df])
5657
else:
5758
df = pd.read_csv(self.save_file_path)
5859
df_run = df.loc[df.run_id == total.run_id]
5960
if len(df_run) < 1:
60-
df = pd.concat([df, pd.DataFrame.from_records([dict(total.values)])])
61+
df = pd.concat([df, new_df])
6162
elif len(df_run) > 1:
6263
logger.warning(
6364
f"CSV contains more than 1 ({len(df_run)})"
6465
+ f" rows with current run ID ({total.run_id})."
6566
+ "Appending instead of updating."
6667
)
67-
df = pd.concat([df, pd.DataFrame.from_records([dict(total.values)])])
68+
df = pd.concat([df, new_df])
6869
else:
6970
df.at[df.run_id == total.run_id, total.values.keys()] = (
7071
total.values.values()

docs/edit/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
author = "BCG GAMMA, Comet.ml, Haverford College, MILA, Data For Good"
2424

2525
# The full version, including alpha/beta/rc tags
26-
release = "3.0.0_rc1"
26+
release = "3.0.0_rc2"
2727

2828

2929
# -- General configuration ---------------------------------------------------

examples/compare_cpu_load_and_RAPL.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ def collect_measurements(expected_load, load_type):
190190
point.temperature = temps["asus_wmi_sensors"][0].current
191191

192192
# Get CPU frequency (average across cores)
193-
freqs = psutil.cpu_freq(percpu=True)
194-
if freqs:
195-
point.cpu_freq = sum(f.current for f in freqs) / len(freqs)
193+
freq = psutil.cpu_freq()
194+
if freq:
195+
point.cpu_freq = freq.current
196196

197197
# point.rapl_power = tracker_rapl._cpu_power.W
198198
# point.estimated_power = tracker_cpu_load._cpu_power.W

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies = [
3131
"fief-client[cli]",
3232
"pandas",
3333
"prometheus_client",
34-
"psutil",
34+
"psutil >= 6.0.0",
3535
"py-cpuinfo",
3636
"pynvml",
3737
"rapidfuzz",
@@ -183,7 +183,7 @@ include = [
183183
]
184184

185185
[tool.bumpver]
186-
current_version = "3.0.0_rc1"
186+
current_version = "3.0.0_rc2"
187187
version_pattern = "MAJOR.MINOR.PATCH[_TAGNUM]"
188188

189189
[tool.bumpver.file_patterns]

requirements.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# - fief-client[cli]
77
# - pandas
88
# - prometheus-client
9-
# - psutil
9+
# - psutil>=6.0.0
1010
# - py-cpuinfo
1111
# - pynvml
1212
# - questionary
@@ -16,24 +16,24 @@
1616
# - typer
1717
#
1818

19-
anyio==4.7.0
19+
anyio==4.8.0
2020
# via httpx
2121
arrow==1.3.0
2222
# via hatch.envs.default
23-
certifi==2024.8.30
23+
certifi==2025.1.31
2424
# via
2525
# httpcore
2626
# httpx
2727
# requests
2828
cffi==1.17.1
2929
# via cryptography
30-
charset-normalizer==3.4.0
30+
charset-normalizer==3.4.1
3131
# via requests
32-
click==8.1.7
32+
click==8.1.8
3333
# via
3434
# hatch.envs.default
3535
# typer
36-
cryptography==44.0.0
36+
cryptography==44.0.1
3737
# via jwcrypto
3838
fief-client==0.20.0
3939
# via hatch.envs.default
@@ -54,35 +54,35 @@ markdown-it-py==3.0.0
5454
# via rich
5555
mdurl==0.1.2
5656
# via markdown-it-py
57-
numpy==2.2.0
57+
numpy==2.2.3
5858
# via pandas
59-
nvidia-ml-py==12.560.30
59+
nvidia-ml-py==12.570.86
6060
# via pynvml
6161
pandas==2.2.3
6262
# via hatch.envs.default
6363
prometheus-client==0.21.1
6464
# via hatch.envs.default
65-
prompt-toolkit==3.0.36
65+
prompt-toolkit==3.0.50
6666
# via questionary
67-
psutil==6.1.0
67+
psutil==7.0.0
6868
# via hatch.envs.default
6969
py-cpuinfo==9.0.0
7070
# via hatch.envs.default
7171
pycparser==2.22
7272
# via cffi
73-
pygments==2.18.0
73+
pygments==2.19.1
7474
# via rich
7575
pynvml==12.0.0
7676
# via hatch.envs.default
7777
python-dateutil==2.9.0.post0
7878
# via
7979
# arrow
8080
# pandas
81-
pytz==2024.2
81+
pytz==2025.1
8282
# via pandas
83-
questionary==2.0.1
83+
questionary==2.1.0
8484
# via hatch.envs.default
85-
rapidfuzz==3.10.1
85+
rapidfuzz==3.12.1
8686
# via hatch.envs.default
8787
requests==2.32.3
8888
# via hatch.envs.default
@@ -109,9 +109,9 @@ typing-extensions==4.12.2
109109
# anyio
110110
# jwcrypto
111111
# typer
112-
tzdata==2024.2
112+
tzdata==2025.1
113113
# via pandas
114-
urllib3==2.2.3
114+
urllib3==2.3.0
115115
# via requests
116116
wcwidth==0.2.13
117117
# via prompt-toolkit

requirements/requirements-api.txt

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# - fief-client[cli]
2929
# - pandas
3030
# - prometheus-client
31-
# - psutil
31+
# - psutil>=6.0.0
3232
# - py-cpuinfo
3333
# - pynvml
3434
# - questionary
@@ -38,9 +38,9 @@
3838
# - typer
3939
#
4040

41-
alembic==1.14.0
41+
alembic==1.14.1
4242
# via hatch.envs.api
43-
anyio==4.7.0
43+
anyio==4.8.0
4444
# via
4545
# httpx
4646
# starlette
@@ -49,29 +49,29 @@ arrow==1.3.0
4949
# via hatch.envs.api
5050
bcrypt==4.2.1
5151
# via hatch.envs.api
52-
certifi==2024.8.30
52+
certifi==2025.1.31
5353
# via
5454
# httpcore
5555
# httpx
5656
# requests
5757
cffi==1.17.1
5858
# via cryptography
59-
charset-normalizer==3.4.0
59+
charset-normalizer==3.4.1
6060
# via requests
61-
click==8.1.7
61+
click==8.1.8
6262
# via
6363
# hatch.envs.api
6464
# typer
6565
# uvicorn
66-
cryptography==44.0.0
66+
cryptography==44.0.1
6767
# via jwcrypto
68-
dependency-injector==4.44.0
68+
dependency-injector==4.45.0
6969
# via hatch.envs.api
7070
dnspython==2.7.0
7171
# via email-validator
7272
email-validator==2.2.0
7373
# via pydantic
74-
fastapi==0.115.6
74+
fastapi==0.115.8
7575
# via
7676
# hatch.envs.api
7777
# fastapi-pagination
@@ -106,7 +106,7 @@ jwcrypto==1.5.6
106106
# via fief-client
107107
makefun==1.15.6
108108
# via fief-client
109-
mako==1.3.8
109+
mako==1.3.9
110110
# via alembic
111111
markdown-it-py==3.0.0
112112
# via rich
@@ -116,11 +116,11 @@ mdurl==0.1.2
116116
# via markdown-it-py
117117
mock==5.1.0
118118
# via hatch.envs.api
119-
numpy==2.2.0
119+
numpy==2.2.3
120120
# via
121121
# hatch.envs.api
122122
# pandas
123-
nvidia-ml-py==12.560.30
123+
nvidia-ml-py==12.570.86
124124
# via pynvml
125125
packaging==24.2
126126
# via pytest
@@ -130,22 +130,22 @@ pluggy==1.5.0
130130
# via pytest
131131
prometheus-client==0.21.1
132132
# via hatch.envs.api
133-
prompt-toolkit==3.0.36
133+
prompt-toolkit==3.0.50
134134
# via questionary
135-
psutil==6.1.0
135+
psutil==7.0.0
136136
# via hatch.envs.api
137137
psycopg2-binary==2.9.10
138138
# via hatch.envs.api
139139
py-cpuinfo==9.0.0
140140
# via hatch.envs.api
141141
pycparser==2.22
142142
# via cffi
143-
pydantic==1.10.19
143+
pydantic==1.10.21
144144
# via
145145
# hatch.envs.api
146146
# fastapi
147147
# fastapi-pagination
148-
pygments==2.18.0
148+
pygments==2.19.1
149149
# via rich
150150
pyjwt==2.10.1
151151
# via hatch.envs.api
@@ -160,15 +160,15 @@ python-dateutil==2.9.0.post0
160160
# pandas
161161
python-dotenv==1.0.1
162162
# via uvicorn
163-
pytz==2024.2
163+
pytz==2025.1
164164
# via pandas
165165
pyyaml==6.0.2
166166
# via
167167
# responses
168168
# uvicorn
169-
questionary==2.0.1
169+
questionary==2.1.0
170170
# via hatch.envs.api
171-
rapidfuzz==3.10.1
171+
rapidfuzz==3.12.1
172172
# via hatch.envs.api
173173
requests==2.32.3
174174
# via
@@ -177,7 +177,7 @@ requests==2.32.3
177177
# responses
178178
requests-mock==1.12.1
179179
# via hatch.envs.api
180-
responses==0.25.3
180+
responses==0.25.6
181181
# via hatch.envs.api
182182
rich==13.9.4
183183
# via
@@ -186,9 +186,7 @@ rich==13.9.4
186186
shellingham==1.5.4
187187
# via typer
188188
six==1.17.0
189-
# via
190-
# dependency-injector
191-
# python-dateutil
189+
# via python-dateutil
192190
sniffio==1.3.1
193191
# via
194192
# anyio
@@ -197,7 +195,7 @@ sqlalchemy==1.4.54
197195
# via
198196
# hatch.envs.api
199197
# alembic
200-
starlette==0.41.3
198+
starlette==0.45.3
201199
# via fastapi
202200
termcolor==2.3.0
203201
# via yaspin
@@ -213,21 +211,21 @@ typing-extensions==4.12.2
213211
# jwcrypto
214212
# pydantic
215213
# typer
216-
tzdata==2024.2
214+
tzdata==2025.1
217215
# via pandas
218-
urllib3==2.2.3
216+
urllib3==2.3.0
219217
# via
220218
# requests
221219
# responses
222-
uvicorn==0.32.1
220+
uvicorn==0.34.0
223221
# via hatch.envs.api
224222
uvloop==0.21.0
225223
# via uvicorn
226-
watchfiles==1.0.3
224+
watchfiles==1.0.4
227225
# via uvicorn
228226
wcwidth==0.2.13
229227
# via prompt-toolkit
230-
websockets==14.1
228+
websockets==15.0
231229
# via uvicorn
232230
yaspin==3.1.0
233231
# via fief-client

0 commit comments

Comments
 (0)