Patchwork [08,of,10,py3] server: write out pid using bytes IO instead of str IO

login
register
mail settings
Submitter Augie Fackler
Date May 29, 2017, 2:32 p.m.
Message ID <c52ab13885c505252bdd.1496068350@imladris.local>
Download mbox | patch
Permalink /patch/21053/
State Accepted
Headers show

Comments

Augie Fackler - May 29, 2017, 2:32 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1496000586 14400
#      Sun May 28 15:43:06 2017 -0400
# Node ID c52ab13885c505252bddf459e3ef86fe1fb8f560
# Parent  44be9a86f325e1cc3d27ce001700652ce2305178
server: write out pid using bytes IO instead of str IO
via Mercurial-devel - May 31, 2017, 10:56 p.m.
On Mon, May 29, 2017 at 7:32 AM, Augie Fackler <raf@durin42.com> wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1496000586 14400
> #      Sun May 28 15:43:06 2017 -0400
> # Node ID c52ab13885c505252bddf459e3ef86fe1fb8f560
> # Parent  44be9a86f325e1cc3d27ce001700652ce2305178
> server: write out pid using bytes IO instead of str IO
>
> diff --git a/mercurial/server.py b/mercurial/server.py
> --- a/mercurial/server.py
> +++ b/mercurial/server.py
> @@ -29,11 +29,11 @@ def runservice(opts, parentfn=None, init
>      def writepid(pid):
>          if opts['pid_file']:
>              if appendpid:
> -                mode = 'a'
> +                mode = 'ab'
>              else:
> -                mode = 'w'
> +                mode = 'wb'
>              fp = open(opts['pid_file'], mode)
> -            fp.write(str(pid) + '\n')
> +            fp.write(str(pid).encode('latin1') + '\n')

Would the usual pattern of ("%d\n" % pid) work?

>              fp.close()
>
>      if opts['daemon'] and not opts['daemon_postexec']:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/server.py b/mercurial/server.py
--- a/mercurial/server.py
+++ b/mercurial/server.py
@@ -29,11 +29,11 @@  def runservice(opts, parentfn=None, init
     def writepid(pid):
         if opts['pid_file']:
             if appendpid:
-                mode = 'a'
+                mode = 'ab'
             else:
-                mode = 'w'
+                mode = 'wb'
             fp = open(opts['pid_file'], mode)
-            fp.write(str(pid) + '\n')
+            fp.write(str(pid).encode('latin1') + '\n')
             fp.close()
 
     if opts['daemon'] and not opts['daemon_postexec']: