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.gu...@windriver.com>
---
 meta/lib/buildstats.py | 4 ++--
 1 file 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),
-- 
2.35.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#167389): 
https://lists.openembedded.org/g/openembedded-core/message/167389
Mute This Topic: https://lists.openembedded.org/mt/92073275/21656
Group Owner: openembedded-core+ow...@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to