You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello.
The nature of this problem is more like a hint than a proper error, thus not filling bug report. (Edit it now seems to be a bug)
(Edit: Relevant link: LibreHardwareMonitor issue #450)
(Edit 2: Finally found the reason! See at the end of this post.)
If you use this app (turing-smart-screen-python) on Windows with default LibreHardwareMonitorLib sensors, you may notice a steady growth of main.exe process (or python.exe, depending how you launched it) memory usage (in my case it's circa +2 MB / minute).
This possible memory leak has been tracked by me to the LibreHardwareMonitorLib sensors python module, and by studying poorly documented LibreHardwareMonitorLib, I've found (one of) the culprit(s):
Every Hardware.Computer.Hardware -> ISensor (being result of enumeration for sensor in hardware.sensors) has a property Values which stores list of recently readed values (assuming readed every Hardware.Update() call) for a default period of one day!
The solution, apply either:
Every time a new sensor is discovered set its property ISensor.ValuesTimeWindow to System.TimeSpan.Zero (first solution, used by me).
From time to time, iterate over every sensor and call its ISensor.ClearValues() method
What I have tried:
First, add this to code:
from System import TimeSpan
TIMESPAN_ZERO = TimeSpan.Zero
For every call on hardware.Update() in .\library\sensors\sensors_librehardwaremonitor.py (there's 3 of this calls in total), traverse the sensors in this hardware and do this (Edit 2 or maybe just once upon module start):
# ...after hw.Update()
for sensor in hw.Sensors:
sensor.ValuesTimeWindow = TIMESPAN_ZERO
Hope it helps!
Edit 2 Finally found the reason why /library/sensors/sensors_librehardwaremonitor.py causes abnormal memory growth!
I've read through source code of LibreHardwareMonitorLib.dll and found that IComputer.Hardware access creates deep copy (or at least some copy) of hardware list. The solution is to cache the handle.Hardware property, here's the full change I did to sensors_librehardwaremonitor.py:
# (the beginning of code, after import clr)
# just in case, import .NET garbage collector
from System import GC
# import TimeSpan object to set sensor value storage time to zero
from System import TimeSpan
TIMESPAN_ZERO = TimeSpan.Zero
# (after handle.Open() )
# cache for hardware list
hw_cache = []
# cache for subhardware of motherboard (no other seems to exist, may be wrong assumption)
mb_subhw_cache = []
# first, cache hardware and subhardware
for hardware in handle.Hardware:
hw_cache.append(hardware)
# cache subhardware of motherboard for fan speed sensors
if hardware.HardwareType = Hardware.HardwareType.Motherboard:
for subhw in hardware.SubHardware:
mb_subhw_cache.append(subhw)
# later on, replace every occurence of "handle.Hardware" into "hw_cache" and in "fan_percent()"
# method replace `mb.SubHardware` with `mb_subhw_cache`
# now, traverse every sensor and set `ValuesTimeWindow` property to Zero TimeSpan
# (this prevents of storing updated sensor values for 1 day by default, see:
# [LibreHardwareMonitor issue #450](https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/issues/450) )
for hw in hw_cache:
for sensor in hw.Sensors:
sensor.ValuesTimeWindow = TIMESPAN_ZERO
for subhw in mb_subhw_cache:
for sensor in subhw.Sensors:
sensor.ValuesTimeWindow = TIMESPAN_ZERO
and eventually, call GC.Collect() (.NET garbage collector) every few minutes (may be not neccessary)
It solved my problem with abnormal memory usage (process Python.exe taking 71 MB initially, after 10 hours it was 280 MB and growing - after my fix Python.exe is still 70,9 MB after 15 hours).
Hope that helps!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello.
The nature of this problem is more like a hint than a proper error, thus not filling bug report. (Edit it now seems to be a bug)
(Edit: Relevant link: LibreHardwareMonitor issue #450)
(Edit 2: Finally found the reason! See at the end of this post.)
If you use this app (turing-smart-screen-python) on Windows with default LibreHardwareMonitorLib sensors, you may notice a steady growth of
main.exe
process (orpython.exe
, depending how you launched it) memory usage (in my case it's circa +2 MB / minute).This possible memory leak has been tracked by me to the LibreHardwareMonitorLib sensors python module, and by studying poorly documented LibreHardwareMonitorLib, I've found (one of) the culprit(s):
Every
Hardware.Computer.Hardware -> ISensor
(being result of enumerationfor sensor in hardware.sensors
) has a propertyValues
which stores list of recently readed values (assuming readed everyHardware.Update()
call) for a default period of one day!The solution, apply either:
ISensor.ValuesTimeWindow
toSystem.TimeSpan.Zero
(first solution, used by me).ISensor.ClearValues()
methodWhat I have tried:
First, add this to code:
For every call on
hardware.Update()
in.\library\sensors\sensors_librehardwaremonitor.py
(there's 3 of this calls in total), traverse the sensors in this hardware and do this (Edit 2 or maybe just once upon module start):Hope it helps!
Edit 2 Finally found the reason why
/library/sensors/sensors_librehardwaremonitor.py
causes abnormal memory growth!I've read through source code of LibreHardwareMonitorLib.dll and found that
IComputer.Hardware
access creates deep copy (or at least some copy) of hardware list. The solution is to cache thehandle.Hardware
property, here's the full change I did tosensors_librehardwaremonitor.py
:and eventually, call
GC.Collect()
(.NET garbage collector) every few minutes (may be not neccessary)It solved my problem with abnormal memory usage (process Python.exe taking 71 MB initially, after 10 hours it was 280 MB and growing - after my fix Python.exe is still 70,9 MB after 15 hours).
Hope that helps!
Beta Was this translation helpful? Give feedback.
All reactions