comparison mercurial/dispatch.py @ 32687:12941a782928

dispatch: do not close stdout and stderr, just flush() instead Since 3a4c0905f357 "util: always force line buffered stdout when stdout is a tty", we have two file objects attached to the same STDOUT_FILENO. If one is closed, the underlying file descriptor is also closed, and writing to the other file object would crash the Python interpreter in a hard way, at least on Windows. So, it seems safer to not close the standard streams. This also matches the behavior of the default sys.stdout/stderr.close(), which never close the FILE* streams in C layer. https://hg.python.org/cpython/file/v2.7.13/Python/sysmodule.c#l1401
author Yuya Nishihara <yuya@tcha.org>
date Sun, 23 Apr 2017 00:31:29 +0900
parents 9929af2b09b4
children 545f69cd6042
comparison
equal deleted inserted replaced
32686:605f124d1146 32687:12941a782928
86 status = (dispatch(req) or 0) & 255 86 status = (dispatch(req) or 0) & 255
87 except error.StdioError as err: 87 except error.StdioError as err:
88 status = -1 88 status = -1
89 if util.safehasattr(req.ui, 'fout'): 89 if util.safehasattr(req.ui, 'fout'):
90 try: 90 try:
91 req.ui.fout.close() 91 req.ui.fout.flush()
92 except IOError as err: 92 except IOError as err:
93 status = -1 93 status = -1
94 if util.safehasattr(req.ui, 'ferr'): 94 if util.safehasattr(req.ui, 'ferr'):
95 if err is not None and err.errno != errno.EPIPE: 95 if err is not None and err.errno != errno.EPIPE:
96 req.ui.ferr.write('abort: %s\n' % err.strerror) 96 req.ui.ferr.write('abort: %s\n' % err.strerror)
97 req.ui.ferr.close() 97 req.ui.ferr.flush()
98 sys.exit(status & 255) 98 sys.exit(status & 255)
99 99
100 def _getsimilar(symbols, value): 100 def _getsimilar(symbols, value):
101 sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio() 101 sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio()
102 # The cutoff for similarity here is pretty arbitrary. It should 102 # The cutoff for similarity here is pretty arbitrary. It should