aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOla x Nilsson <ola.x.nilsson@axis.com>2019-12-20 15:23:19 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-12-30 23:39:33 +0000
commit6fa8a18ea4994031fdd1253fe363c5d8eeeba456 (patch)
tree177a4d9ea310bf09a4f001bbe1d2324853e00c70
parent923aff060d8aba8456979c35b16d300ba7c13ff9 (diff)
downloadbitbake-contrib-6fa8a18ea4994031fdd1253fe363c5d8eeeba456.tar.gz
prserv/serv: Use with while reading pidfile
Signed-off-by: Ola x Nilsson <olani@axis.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/prserv/serv.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
index 3124b0799..25dcf8a0e 100644
--- a/lib/prserv/serv.py
+++ b/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