From: Aryaman Gupta Date: Wed, 29 Jun 2022 20:08:20 +0000 (-0400) Subject: buildstats.py: close /proc/pressure/cpu file descriptor X-Git-Tag: lucaceresoli/bug-15201-perf-libtraceevent-missing~3751 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=643653160cd77d346cdc9b9ec25c7212c7dfe176;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git buildstats.py: close /proc/pressure/cpu file descriptor 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 Signed-off-by: Richard Purdie --- diff --git a/meta/lib/buildstats.py b/meta/lib/buildstats.py index 5d32a819067..99a8303d5e2 100644 --- a/meta/lib/buildstats.py +++ b/meta/lib/buildstats.py @@ -23,8 +23,8 @@ class SystemStats: # 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),