Use python 'with' symantics to ensure that the /proc/pressure/cpu file
descriptor used in SystemStats init is closed. Previously, this would
lead to a single file descriptor being leaked. For example:
ResourceWarning: unclosed file <_io.BufferedReader name='/proc/pressure/cpu'>
Signed-off-by: Aryaman Gupta <aryaman.gupta@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
# and ensure that the reduce_proc_pressure directory is not created.
if os.path.exists("/proc/pressure"):
try:
- source = open('/proc/pressure/cpu', 'rb')
- source.read()
+ with open('/proc/pressure/cpu', 'rb') as source:
+ source.read()
pressuredir = os.path.join(bsdir, 'reduced_proc_pressure')
bb.utils.mkdirhier(pressuredir)
file_handlers.extend([('pressure/cpu', self._reduce_pressure),