From 9b0f2f2e79c72855e654765d9c072109eed3d1e9 Mon Sep 17 00:00:00 2001 From: Ola x Nilsson Date: Fri, 20 Dec 2019 15:23:19 +0100 Subject: bitbake: prserv/serv: Use with while reading pidfile (Bitbake rev: e731f72ca86629eb935bb1c4f7323421a125aace) Signed-off-by: Ola x Nilsson Signed-off-by: Richard Purdie (cherry picked from commit 6fa8a18ea4994031fdd1253fe363c5d8eeeba456) Signed-off-by: Armin Kuster Signed-off-by: Richard Purdie --- bitbake/lib/prserv/serv.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'bitbake/lib/prserv') diff --git a/bitbake/lib/prserv/serv.py b/bitbake/lib/prserv/serv.py index 6d8142fcc4..446e1fe127 100644 --- a/bitbake/lib/prserv/serv.py +++ b/bitbake/lib/prserv/serv.py @@ -292,10 +292,9 @@ class PRServer(SimpleXMLRPCServer): logger.addHandler(streamhandler) # write pidfile - pid = str(os.getpid()) - pf = open(self.pidfile, 'w') - pf.write("%s\n" % pid) - pf.close() + pid = str(os.getpid()) + with open(self.pidfile, 'w') as pf: + pf.write("%s\n" % pid) self.work_forever() self.delpid() @@ -353,9 +352,8 @@ def start_daemon(dbfile, host, port, logfile): ip = socket.gethostbyname(host) pidfile = PIDPREFIX % (ip, port) try: - pf = open(pidfile,'r') - pid = int(pf.readline().strip()) - pf.close() + with open(pidfile) as pf: + pid = int(pf.readline().strip()) except IOError: pid = None -- cgit v1.2.3-54-g00ecf