comparison tests/tinyproxy.py @ 32906:23b07333a8b2

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
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 18 Jun 2017 21:31:53 -0400
parents b2a41a826d71
children 88c1d13b637b
comparison
equal deleted inserted replaced
32905:2851b24eecc4 32906:23b07333a8b2
51 def log_request(self, code='-', size='-'): 51 def log_request(self, code='-', size='-'):
52 xheaders = [h for h in self.headers.items() if h[0].startswith('x-')] 52 xheaders = [h for h in self.headers.items() if h[0].startswith('x-')]
53 self.log_message('"%s" %s %s%s', 53 self.log_message('"%s" %s %s%s',
54 self.requestline, str(code), str(size), 54 self.requestline, str(code), str(size),
55 ''.join([' %s:%s' % h for h in sorted(xheaders)])) 55 ''.join([' %s:%s' % h for h in sorted(xheaders)]))
56 # Flush for Windows, so output isn't lost on TerminateProcess()
57 sys.stderr.flush()
56 58
57 def _connect_to(self, netloc, soc): 59 def _connect_to(self, netloc, soc):
58 i = netloc.find(':') 60 i = netloc.find(':')
59 if i >= 0: 61 if i >= 0:
60 host_port = netloc[:i], int(netloc[i + 1:]) 62 host_port = netloc[:i], int(netloc[i + 1:])