[oe-commits] [bitbake] 20/25: prserv/serv: Use with while reading pidfile

git at git.openembedded.org git at git.openembedded.org
Sat Jan 11 11:07:16 UTC 2020


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch 1.44
in repository bitbake.

commit e731f72ca86629eb935bb1c4f7323421a125aace
Author: Ola x Nilsson <ola.x.nilsson at axis.com>
AuthorDate: Fri Dec 20 15:23:19 2019 +0100

    prserv/serv: Use with while reading pidfile
    
    Signed-off-by: Ola x Nilsson <olani at axis.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
    (cherry picked from commit 6fa8a18ea4994031fdd1253fe363c5d8eeeba456)
    Signed-off-by: Armin Kuster <akuster808 at gmail.com>
---
 lib/prserv/serv.py | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
index 6d8142f..446e1fe 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
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list