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

Submitted by Ola X Nilsson on Dec. 20, 2019, 2:23 p.m. | Patch ID: 168237

Details

Message ID 20191220142320.17724-1-olani@axis.com
State New
Headers show

Commit Message

Ola X Nilsson Dec. 20, 2019, 2:23 p.m.
Signed-off-by: Ola x Nilsson <olani@axis.com>
---
 lib/prserv/serv.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

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
 

Comments

Peter Kjellerstedt Dec. 20, 2019, 5:22 p.m.
> -----Original Message-----
> From: bitbake-devel-bounces@lists.openembedded.org <bitbake-devel-
> bounces@lists.openembedded.org> On Behalf Of Ola x Nilsson
> Sent: den 20 december 2019 15:23
> To: bitbake-devel@lists.openembedded.org
> Subject: [bitbake-devel] [PATCH 1/2] bitbake: prserv/serv: Use with while
> reading pidfile
> 
> Signed-off-by: Ola x Nilsson <olani@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()

//Peter
Richard Purdie Dec. 30, 2019, 11 a.m.
On Fri, 2019-12-20 at 17:22 +0000, Peter Kjellerstedt wrote:
> > -----Original Message-----
> > From: bitbake-devel-bounces@lists.openembedded.org <bitbake-devel-
> > bounces@lists.openembedded.org> On Behalf Of Ola x Nilsson
> > Sent: den 20 december 2019 15:23
> > To: bitbake-devel@lists.openembedded.org
> > Subject: [bitbake-devel] [PATCH 1/2] bitbake: prserv/serv: Use with
> > while
> > reading pidfile
> > 
> > Signed-off-by: Ola x Nilsson <olani@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
Peter Kjellerstedt Dec. 30, 2019, 12:20 p.m.
> -----Original Message-----
> From: Richard Purdie <richard.purdie@linuxfoundation.org>
> Sent: den 30 december 2019 12:00
> To: Peter Kjellerstedt <peter.kjellerstedt@axis.com>; Ola x Nilsson
> <Ola.x.Nilsson@axis.com>; bitbake-devel@lists.openembedded.org
> Subject: Re: [bitbake-devel] [PATCH 1/2] bitbake: prserv/serv: Use with
> while reading pidfile
> 
> On Fri, 2019-12-20 at 17:22 +0000, Peter Kjellerstedt wrote:
> > > -----Original Message-----
> > > From: bitbake-devel-bounces@lists.openembedded.org <bitbake-devel-
> > > bounces@lists.openembedded.org> On Behalf Of Ola x Nilsson
> > > Sent: den 20 december 2019 15:23
> > > To: bitbake-devel@lists.openembedded.org
> > > Subject: [bitbake-devel] [PATCH 1/2] bitbake: prserv/serv: Use with
> > > while
> > > reading pidfile
> > >
> > > Signed-off-by: Ola x Nilsson <olani@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

Well, I mainly meant for Ola to send an updated patch with both hunks, but 
I guess I should have stated that in my response. Anyway, thanks for taking 
care of it.

//Peter