diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2015-08-16 14:00:31 -0500 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2015-08-16 14:00:32 -0500 |
| commit | d98e1729b3e1e83d796727d59be610dae4254611 (patch) | |
| tree | 9fd00fd96b66dd74f2ebd5eba77279961022e29c | |
| parent | 57ec990dad132c98b601006fd83fe50125cc647a (diff) | |
| download | flake8-bug/69.tar.gz | |
Handle EPIPE IOErrors when using more than 1 jobbug/69
If someone is using flake8 and piping it to a command like `head`, the
command they are piping flake8's output too may close the pipe earlier
than flake8 expects. To avoid extraneous exception output being printed,
we now catch IOErrors and check their errnos to ensure they're something
we know we can ignore.
This also provides flexibility to add further errnos for ignoring on a
case-by-case basis.
Closes #69
| -rw-r--r-- | flake8/reporter.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/flake8/reporter.py b/flake8/reporter.py index 5fc2743..1df3d9e 100644 --- a/flake8/reporter.py +++ b/flake8/reporter.py @@ -2,6 +2,7 @@ # Adapted from a contribution of Johan Dahlin import collections +import errno import re import sys try: @@ -18,6 +19,20 @@ class BaseQReport(pep8.BaseReport): """Base Queue Report.""" _loaded = False # Windows support + # Reasoning for ignored error numbers is in-line below + ignored_errors = set([ + # EPIPE: Added by sigmavirus24 + # > If output during processing is piped to something that may close + # > its own stdin before we've finished printing results, we need to + # > catch a Broken pipe error and continue on. + # > (See also: https://gitlab.com/pycqa/flake8/issues/69) + errno.EPIPE, + # NOTE(sigmavirus24): When adding to this list, include the reasoning + # on the lines before the error code and always append your error + # code. Further, please always add a trailing `,` to reduce the visual + # noise in diffs. + ]) + def __init__(self, options): assert options.jobs > 0 super(BaseQReport, self).__init__(options) @@ -74,6 +89,11 @@ class BaseQReport(pep8.BaseReport): self._process_main() except KeyboardInterrupt: pass + except IOError as ioerr: + # If we happen across an IOError that we aren't certain can/should + # be ignored, we should re-raise the exception. + if ioerr.errno not in self.ignored_errors: + raise finally: # ensure all output is flushed before main process continues sys.stdout.flush() |
