@@ -37,8 +37,30 @@ class BrokenStdoutLoggingError(Exception):
37
37
pass
38
38
39
39
40
- if PY2 :
41
- # BrokenPipeError does not exist in Python 2.
40
+ # BrokenPipeError does not exist in Python 2 and, in addition, manifests
41
+ # differently in Windows and non-Windows.
42
+ if WINDOWS :
43
+ # In Windows, a broken pipe can show up as EINVAL rather than EPIPE:
44
+ # https://bugs.python.org/issue19612
45
+ # https://bugs.python.org/issue30418
46
+ if PY2 :
47
+ def _is_broken_pipe_error (exc_class , exc ):
48
+ """See the docstring for non-Windows Python 3 below."""
49
+ return (exc_class is IOError and
50
+ exc .errno in (errno .EINVAL , errno .EPIPE ))
51
+ else :
52
+ # In Windows, a broken pipe IOError became OSError in Python 3.
53
+ def _is_broken_pipe_error (exc_class , exc ):
54
+ """See the docstring for non-Windows Python 3 below."""
55
+ return ((exc_class is BrokenPipeError ) or # noqa: F821
56
+ (exc_class is OSError and
57
+ exc .errno in (errno .EINVAL , errno .EPIPE )))
58
+ elif PY2 :
59
+ def _is_broken_pipe_error (exc_class , exc ):
60
+ """See the docstring for non-Windows Python 3 below."""
61
+ return (exc_class is IOError and exc .errno == errno .EPIPE )
62
+ else :
63
+ # Then we are in the non-Windows Python 3 case.
42
64
def _is_broken_pipe_error (exc_class , exc ):
43
65
"""
44
66
Return whether an exception is a broken pipe error.
@@ -47,10 +69,6 @@ def _is_broken_pipe_error(exc_class, exc):
47
69
exc_class: an exception class.
48
70
exc: an exception instance.
49
71
"""
50
- return (exc_class is IOError and exc .errno == errno .EPIPE )
51
-
52
- else :
53
- def _is_broken_pipe_error (exc_class , exc ):
54
72
return (exc_class is BrokenPipeError ) # noqa: F821
55
73
56
74
0 commit comments