Skip to content
Myr

Prevent error messages/exit code 120 after exiting on EPIPE

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Frankie Robertson · committed by David Lord · parent 6e410dc · Browse files · 2 files+28 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+28 added−1 removed

  • other:+28 added−1 removed

2 files+28 added−1 removed

modified:click/core.py+4 added-1 removed
5 unmodified lines
6from itertools import repeat7from functools import update_wrapper89from .types import convert_type, IntRange, BOOL10from .utils import make_str, make_default_short_help, echo, get_os_args10from .utils import PacifyFlushWrapper, make_str, make_default_short_help, \11 echo, get_os_args12from .exceptions import ClickException, UsageError, BadParameter, Abort, \13 MissingParameter, Exit14from .termui import prompt, confirm, style15from .formatting import HelpFormatter, join_options
718 unmodified lines
734 e.show()735 sys.exit(e.exit_code)736 except IOError as e:737 if e.errno == errno.EPIPE:738 sys.stdout = PacifyFlushWrapper(sys.stdout)739 sys.stderr = PacifyFlushWrapper(sys.stderr)740 sys.exit(1)741 else:742 raise743 except Exit as e:
1113 unmodified lines
modified:click/utils.py+24 added
412 unmodified lines
413 '~/Library/Application Support'), app_name)414 return os.path.join(415 os.environ.get('XDG_CONFIG_HOME', os.path.expanduser('~/.config')),416 _posixify(app_name))417418419class PacifyFlushWrapper(object):420 """This wrapper is used to catch and suppress BrokenPipeErrors resulting421 from ``.flush()`` being called on broken pipe during the shutdown/final-GC422 of the Python interpreter. Notably ``.flush()`` is always called on423 ``sys.stdout`` and ``sys.stderr``. So as to have minimal impact on any424 other cleanup code, and the case where the underlying file is not a broken425 pipe, all calls and attributes are proxied.426 """427428 def __init__(self, wrapped):429 self.wrapped = wrapped430431 def flush(self):432 try:433 self.wrapped.flush()434 except IOError as e:435 import errno436 if e.errno != errno.EPIPE:437 raise438439 def __getattr__(self, attr):440 return getattr(self.wrapped, attr)