Mercurial > hg
comparison mercurial/dispatch.py @ 36637:e8c361316803
py3: silence the final IOError by closing stdout/err slightly early
Fixes the following test failure:
$ hg status >/dev/full
abort: No space left on device
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' ...
OSError: [Errno 28] No space left on device
[120]
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 02 Mar 2018 22:35:20 -0500 |
parents | c263c684da91 |
children | 77f98867538f |
comparison
equal
deleted
inserted
replaced
36636:c263c684da91 | 36637:e8c361316803 |
---|---|
103 req.ui.ferr.flush() | 103 req.ui.ferr.flush() |
104 # There's not much we can do about an I/O error here. So (possibly) | 104 # There's not much we can do about an I/O error here. So (possibly) |
105 # change the status code and move on. | 105 # change the status code and move on. |
106 except IOError: | 106 except IOError: |
107 status = -1 | 107 status = -1 |
108 | |
109 _silencestdio() | |
108 sys.exit(status & 255) | 110 sys.exit(status & 255) |
109 | 111 |
110 if pycompat.ispy3: | 112 if pycompat.ispy3: |
111 def _initstdio(): | 113 def _initstdio(): |
112 pass | 114 pass |
115 | |
116 def _silencestdio(): | |
117 for fp in (sys.stdout, sys.stderr): | |
118 # Check if the file is okay | |
119 try: | |
120 fp.flush() | |
121 continue | |
122 except IOError: | |
123 pass | |
124 # Otherwise mark it as closed to silence "Exception ignored in" | |
125 # message emitted by the interpreter finalizer. Be careful to | |
126 # not close util.stdout, which may be a fdopen-ed file object and | |
127 # its close() actually closes the underlying file descriptor. | |
128 try: | |
129 fp.close() | |
130 except IOError: | |
131 pass | |
113 else: | 132 else: |
114 def _initstdio(): | 133 def _initstdio(): |
115 for fp in (sys.stdin, sys.stdout, sys.stderr): | 134 for fp in (sys.stdin, sys.stdout, sys.stderr): |
116 util.setbinary(fp) | 135 util.setbinary(fp) |
136 | |
137 def _silencestdio(): | |
138 pass | |
117 | 139 |
118 def _getsimilar(symbols, value): | 140 def _getsimilar(symbols, value): |
119 sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio() | 141 sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio() |
120 # The cutoff for similarity here is pretty arbitrary. It should | 142 # The cutoff for similarity here is pretty arbitrary. It should |
121 # probably be investigated and tweaked. | 143 # probably be investigated and tweaked. |