Mercurial > public > mercurial-scm > hg
comparison mercurial/ui.py @ 31963:1bfb9a63b98e
stdio: raise StdioError if something goes wrong in ui.flush
The prior code used to ignore all errors, which was intended to
deal with a decade-old problem with writing to broken pipes on
Windows.
However, that code inadvertantly went a lot further, making it
impossible to detect *all* I/O errors on stdio ... but only sometimes.
What actually happened was that if Mercurial wrote less than a stdio
buffer's worth of output (the overwhelmingly common case for most
commands), any error that occurred would get swallowed here. But
if the buffering strategy changed, an unhandled IOError could be
raised from any number of other locations.
Because we now have a top-level StdioError handler, and ui._write
and ui._write_err (and now flush!) will raise that exception, we
have one rational place to detect and handle these errors.
author | Bryan O'Sullivan <bryano@fb.com> |
---|---|
date | Tue, 11 Apr 2017 14:54:12 -0700 |
parents | e9646ff34d55 |
children | bf5e13e38390 |
comparison
equal
deleted
inserted
replaced
31962:e9646ff34d55 | 31963:1bfb9a63b98e |
---|---|
805 | 805 |
806 def flush(self): | 806 def flush(self): |
807 # opencode timeblockedsection because this is a critical path | 807 # opencode timeblockedsection because this is a critical path |
808 starttime = util.timer() | 808 starttime = util.timer() |
809 try: | 809 try: |
810 try: self.fout.flush() | 810 try: |
811 except (IOError, ValueError): pass | 811 self.fout.flush() |
812 try: self.ferr.flush() | 812 except IOError as err: |
813 except (IOError, ValueError): pass | 813 raise error.StdioError(err) |
814 finally: | |
815 try: | |
816 self.ferr.flush() | |
817 except IOError as err: | |
818 raise error.StdioError(err) | |
814 finally: | 819 finally: |
815 self._blockedtimes['stdio_blocked'] += \ | 820 self._blockedtimes['stdio_blocked'] += \ |
816 (util.timer() - starttime) * 1000 | 821 (util.timer() - starttime) * 1000 |
817 | 822 |
818 def _isatty(self, fh): | 823 def _isatty(self, fh): |