diff mbox series

bitbake-server: use with to avoid ResourceWarning

Message ID 20241008170313.2392646-2-chris.laplante@agilent.com
State Accepted, archived
Commit 8dbf1ec8139d9dd7f52c1773cccbe7696b3ec1b4
Headers show
Series bitbake-server: use with to avoid ResourceWarning | expand

Commit Message

chris.laplante@agilent.com Oct. 8, 2024, 5:03 p.m. UTC
From: Chris Laplante <chris.laplante@agilent.com>

Prevents the following warning in bitbake-cookerdaemon.log:

2386729 10:54:16.195427 Exiting (socket: True)
2386729 10:54:16.201065 Exiting as we could obtain the lock
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/laplante/main_yocto/build/bitbake-cookerdaemon.log' mode='a+' encoding='UTF-8'>

Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
---
 bin/bitbake-server | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/bin/bitbake-server b/bin/bitbake-server
index 454a3919aa..e367ec2c12 100755
--- a/bin/bitbake-server
+++ b/bin/bitbake-server
@@ -38,9 +38,9 @@  if xmlrpcinterface[0] == "None":
 with open('/dev/null', 'r') as si:
     os.dup2(si.fileno(), sys.stdin.fileno())
 
-so = open(logfile, 'a+')
-os.dup2(so.fileno(), sys.stdout.fileno())
-os.dup2(so.fileno(), sys.stderr.fileno())
+with open(logfile, 'a+') as so:
+    os.dup2(so.fileno(), sys.stdout.fileno())
+    os.dup2(so.fileno(), sys.stderr.fileno())
 
 # Have stdout and stderr be the same so log output matches chronologically
 # and there aren't two seperate buffers