equal
deleted
inserted
replaced
207 |
207 |
208 try: |
208 try: |
209 for hname, cmd in hooks: |
209 for hname, cmd in hooks: |
210 if oldstdout == -1 and _redirect: |
210 if oldstdout == -1 and _redirect: |
211 try: |
211 try: |
212 stdoutno = sys.stdout.fileno() |
212 stdoutno = util.stdout.fileno() |
213 stderrno = sys.stderr.fileno() |
213 stderrno = util.stderr.fileno() |
214 # temporarily redirect stdout to stderr, if possible |
214 # temporarily redirect stdout to stderr, if possible |
215 if stdoutno >= 0 and stderrno >= 0: |
215 if stdoutno >= 0 and stderrno >= 0: |
216 sys.stdout.flush() |
216 util.stdout.flush() |
217 oldstdout = os.dup(stdoutno) |
217 oldstdout = os.dup(stdoutno) |
218 os.dup2(stderrno, stdoutno) |
218 os.dup2(stderrno, stdoutno) |
219 except (OSError, AttributeError): |
219 except (OSError, AttributeError): |
220 # files seem to be bogus, give up on redirecting (WSGI, etc) |
220 # files seem to be bogus, give up on redirecting (WSGI, etc) |
221 pass |
221 pass |
253 res[hname] = r, raised |
253 res[hname] = r, raised |
254 |
254 |
255 # The stderr is fully buffered on Windows when connected to a pipe. |
255 # The stderr is fully buffered on Windows when connected to a pipe. |
256 # A forcible flush is required to make small stderr data in the |
256 # A forcible flush is required to make small stderr data in the |
257 # remote side available to the client immediately. |
257 # remote side available to the client immediately. |
258 sys.stderr.flush() |
258 util.stderr.flush() |
259 finally: |
259 finally: |
260 if _redirect and oldstdout >= 0: |
260 if _redirect and oldstdout >= 0: |
261 sys.stdout.flush() # write hook output to stderr fd |
261 util.stdout.flush() # write hook output to stderr fd |
262 os.dup2(oldstdout, stdoutno) |
262 os.dup2(oldstdout, stdoutno) |
263 os.close(oldstdout) |
263 os.close(oldstdout) |
264 |
264 |
265 return res |
265 return res |