comparison mercurial/util.py @ 36991:d683c7367989

wireproto: explicitly flush stdio to prevent stalls on Windows This is the key to fixing the hangs on Windows in D2720[1]. I put flushes in a bunch of other places that didn't help, but I suspect that's more a lack of test coverage than anything else. Chasing down stuff like this is pretty painful. I'm wondering if we can put a proxy around sys.stderr (and sys.stdout?) on Windows (only when daemonized?) that will flush on every write (or at least every write with a '\n'). [1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2018-March/113352.html
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 10 Mar 2018 23:58:01 -0500
parents 644a02f6b34f
children 8453699a1f21
comparison
equal deleted inserted replaced
36990:b6a4881cec19 36991:d683c7367989
713 self.writes = writes 713 self.writes = writes
714 714
715 def _writedata(self, data): 715 def _writedata(self, data):
716 if not self.logdata: 716 if not self.logdata:
717 self.fh.write('\n') 717 self.fh.write('\n')
718 self.fh.flush()
718 return 719 return
719 720
720 # Simple case writes all data on a single line. 721 # Simple case writes all data on a single line.
721 if b'\n' not in data: 722 if b'\n' not in data:
722 self.fh.write(': %s\n' % escapedata(data)) 723 self.fh.write(': %s\n' % escapedata(data))
724 self.fh.flush()
723 return 725 return
724 726
725 # Data with newlines is written to multiple lines. 727 # Data with newlines is written to multiple lines.
726 self.fh.write(':\n') 728 self.fh.write(':\n')
727 lines = data.splitlines(True) 729 lines = data.splitlines(True)
728 for line in lines: 730 for line in lines:
729 self.fh.write('%s> %s\n' % (self.name, escapedata(line))) 731 self.fh.write('%s> %s\n' % (self.name, escapedata(line)))
732 self.fh.flush()
730 733
731 def read(self, res, size=-1): 734 def read(self, res, size=-1):
732 if not self.reads: 735 if not self.reads:
733 return 736 return
734 # Python 3 can return None from reads at EOF instead of empty strings. 737 # Python 3 can return None from reads at EOF instead of empty strings.