Skip to content

Commit c3257df

Browse files
committed
Do not use psutil virtual_memory used/free: not reliable. Use total/available instead
1 parent ebc32cd commit c3257df

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

library/sensors/sensors_python.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,15 @@ def virtual_percent() -> float:
268268

269269
@staticmethod
270270
def virtual_used() -> int: # In bytes
271-
return psutil.virtual_memory().used
271+
# Do not use psutil.virtual_memory().used: from https://psutil.readthedocs.io/en/latest/#memory
272+
# "It is calculated differently depending on the platform and designed for informational purposes only"
273+
return psutil.virtual_memory().total - psutil.virtual_memory().available
272274

273275
@staticmethod
274276
def virtual_free() -> int: # In bytes
275-
return psutil.virtual_memory().free
277+
# Do not use psutil.virtual_memory().free: from https://psutil.readthedocs.io/en/latest/#memory
278+
# "note that this doesn’t reflect the actual memory available (use available instead)."
279+
return psutil.virtual_memory().available
276280

277281

278282
class Disk(sensors.Disk):

0 commit comments

Comments
 (0)