# HG changeset patch # User Matt Mackall # Date 2012-11-26 23:48:39 # Node ID 2c63896783e31908f18088a7e9c583de6ec530bf # Parent 6180dcb29ec531c5d7457005ef142ea304ef49d8 hooks: be even more forgiven of non-fd descriptors (issue3711) Looks like there are instances where sys.stdout/stderr contain file handles that are invalid. We should be tolerant of this for hook I/O redirection, as our primary concern is not garbling our own output stream. diff --git a/mercurial/hook.py b/mercurial/hook.py --- a/mercurial/hook.py +++ b/mercurial/hook.py @@ -158,8 +158,8 @@ def hook(ui, repo, name, throw=False, ** sys.__stdout__.flush() oldstdout = os.dup(stdoutno) os.dup2(stderrno, stdoutno) - except AttributeError: - # __stdout__/__stderr__ has no fileno(), not a real file + except (OSError, AttributeError): + # files seem to be bogus, give up on redirecting (WSGI, etc) pass if util.safehasattr(cmd, '__call__'):