Skip to content

Commit 08b769b

Browse files
authored
Merge pull request #462 from mathoudebine/fix/450-used-ram-meaningless-on-linux-+-give-wrong-total
2 parents ebc32cd + c3257df commit 08b769b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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)