diff options
author | Aryaman Gupta <aryaman.gupta@windriver.com> | 2022-06-29 16:08:20 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-06-30 10:54:46 +0100 |
commit | 4678581ea054b1eef305ff5bc4bd40d8b74374ca (patch) | |
tree | ed9f3b551328e3ff624b0076222ff0794c7c1f3a | |
parent | a26721d83b9b492b474f171bfc0a73a94e4147f9 (diff) | |
download | poky-4678581ea054b1eef305ff5bc4bd40d8b74374ca.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'>
(From OE-Core rev: 643653160cd77d346cdc9b9ec25c7212c7dfe176)
Signed-off-by: Aryaman Gupta <aryaman.gupta@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/buildstats.py | 4 |
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: | |||
23 | # and ensure that the reduce_proc_pressure directory is not created. | 23 | # and ensure that the reduce_proc_pressure directory is not created. |
24 | if os.path.exists("/proc/pressure"): | 24 | if os.path.exists("/proc/pressure"): |
25 | try: | 25 | try: |
26 | source = open('/proc/pressure/cpu', 'rb') | 26 | with open('/proc/pressure/cpu', 'rb') as source: |
27 | source.read() | 27 | source.read() |
28 | pressuredir = os.path.join(bsdir, 'reduced_proc_pressure') | 28 | pressuredir = os.path.join(bsdir, 'reduced_proc_pressure') |
29 | bb.utils.mkdirhier(pressuredir) | 29 | bb.utils.mkdirhier(pressuredir) |
30 | file_handlers.extend([('pressure/cpu', self._reduce_pressure), | 30 | file_handlers.extend([('pressure/cpu', self._reduce_pressure), |