[PATCH 1 of 2] tinyproxy: explicitly flush logged messages

Matt Harbison mharbison72 at gmail.com
Mon Jun 19 04:58:29 UTC 2017


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1497835913 14400
#      Sun Jun 18 21:31:53 2017 -0400
# Node ID 8fd2d66049d936d2cc501ad9a466fb5e67ed8ac2
# Parent  07d5a503124caed05e1300a5208240764882c831
tinyproxy: explicitly flush logged messages

On Windows, output streams are buffered when redirected to a file, and
TerminateProcess() apparently doesn't trigger a flush.  This left
test-http-proxy.t missing part of the last line when it cat'd proxy.log[1].

Flushing stderr is all that is needed (on py27 anyway).  I originally flushed
stdout too, but that added additional output to the log:

     $ cat proxy.log
  +  Accept: $LOCALIP (localhost)\r (esc)
  +  Serving HTTP on 0.0.0.0 port 20810 ...\r (esc)
  +       connect to localhost:$HGPORT\r (esc)
     * - - [*] "GET http://localhost:$HGPORT/?cmd=capabilities HTTP/1.1" - - (glob)
  +       bye\r (esc)
  +       connect to localhost:$HGPORT\r (esc)
     * - - [*] "GET http://localhost:$HGPORT/?cmd=branchmap HTTP/1.1" - - x-hgproto-1:0.1 0.2 comp=*zlib,none,bzip2 (glob)
  +       bye\r (esc)
  +       connect to localhost:$HGPORT\r (esc)
     * - - [*] "GET http://localhost:$HGPORT/?cmd=stream_out HTTP/1.1" - - x-hgproto-1:0.1 0.2 comp=*zlib,none,bzip2 (glob)
  +       bye\r (esc)
  +       connect to localhost:$HGPORT\r (esc)
 ...

[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-April/096987.html

diff --git a/tests/tinyproxy.py b/tests/tinyproxy.py
--- a/tests/tinyproxy.py
+++ b/tests/tinyproxy.py
@@ -53,6 +53,8 @@
         self.log_message('"%s" %s %s%s',
                          self.requestline, str(code), str(size),
                          ''.join([' %s:%s' % h for h in sorted(xheaders)]))
+        # Flush for Windows, so output isn't lost on TerminateProcess()
+        sys.stderr.flush()
 
     def _connect_to(self, netloc, soc):
         i = netloc.find(':')


More information about the Mercurial-devel mailing list