summaryrefslogtreecommitdiffstats
path: root/meta/lib/buildstats.py
diff options
context:
space:
mode:
authorAryaman Gupta <aryaman.gupta@windriver.com>2022-06-29 16:08:20 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-06-30 10:54:44 +0100
commit643653160cd77d346cdc9b9ec25c7212c7dfe176 (patch)
treee6bc5d13cb1fa2ed8f2af42b5cb9065a825de114 /meta/lib/buildstats.py
parent2b76c8e5fc8802bbe54371119e6bf6312bf2a8ec (diff)
downloadopenembedded-core-643653160cd77d346cdc9b9ec25c7212c7dfe176.tar.gz
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 <aryaman.gupta@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/buildstats.py')
-rw-r--r--meta/lib/buildstats.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/meta/lib/buildstats.py b/meta/lib/buildstats.py
index 5d32a81906..99a8303d5e 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),