[bitbake-devel] [PATCH 1/2] bitbake: prserv/serv: Use with while reading pidfile

Richard Purdie richard.purdie at linuxfoundation.org
Mon Dec 30 11:00:26 UTC 2019


On Fri, 2019-12-20 at 17:22 +0000, Peter Kjellerstedt wrote:
> > -----Original Message-----
> > From: bitbake-devel-bounces at lists.openembedded.org <bitbake-devel-
> > bounces at lists.openembedded.org> On Behalf Of Ola x Nilsson
> > Sent: den 20 december 2019 15:23
> > To: bitbake-devel at lists.openembedded.org
> > Subject: [bitbake-devel] [PATCH 1/2] bitbake: prserv/serv: Use with
> > while
> > reading pidfile
> > 
> > Signed-off-by: Ola x Nilsson <olani at axis.com>
> > ---
> >  lib/prserv/serv.py | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> > 
> > diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
> > index 3124b079..708b2e0a 100644
> > --- a/lib/prserv/serv.py
> > +++ b/lib/prserv/serv.py
> > @@ -353,9 +353,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
> > 
> > --
> > 2.11.0
> 
> This only half the patch. Please add the following:
> 
> @@ -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()
> 

I've handled this but asking me to manually merge hunks of patches
together before applying them seems a little potentially error prone?

Cheers,

Richard



More information about the bitbake-devel mailing list