]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
buildstats.py: close /proc/pressure/cpu file descriptor
authorAryaman Gupta <aryaman.gupta@windriver.com>
Wed, 29 Jun 2022 20:08:20 +0000 (16:08 -0400)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 30 Jun 2022 09:54:44 +0000 (10:54 +0100)
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>
meta/lib/buildstats.py

index 5d32a819067f352f3118cc81502ee15ee2a0eceb..99a8303d5e221a44899d9503bbf903943c202882 100644 (file)
@@ -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),