Skip to content
Myr

Handle SIGPIPE in click.echo().

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

When the output of a click program is sent to another program via a pipe, and the pipe is closed prematurely, click.echo() was printing an exception backtrace instead of silently exiting like most command line utilities. Fix #626 Fix #625

authored by Oscar Bonilla · committed by Markus Unterwaditzer · parent 501b641 · Browse files · 3 files+8 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

3 files+8 added−1 removed

  • tests:+1 added−1 removed
  • other:+7 added−0 removed

3 files+8 added−1 removed

modified:click/core.py+6 added
1import errno2import os3import sys4from contextlib import contextmanager5from itertools import repeat
699 unmodified lines
705 if not standalone_mode:706 raise707 e.show()708 sys.exit(e.exit_code)709 except IOError as e:710 if e.errno == errno.EPIPE:711 sys.exit(1)712 else:713 raise714 except Abort:715 if not standalone_mode:716 raise717 echo('Aborted!', file=sys.stderr)
1027 unmodified lines
modified:tests/test_imports.py+1 added-1 removed
30 unmodified lines
3132ALLOWED_IMPORTS = set([33 'weakref', 'os', 'struct', 'collections', 'sys', 'contextlib',34 'functools', 'stat', 're', 'codecs', 'inspect', 'itertools', 'io',35 'threading', 'colorama'35 'threading', 'colorama', 'errno'36])3738if WIN:39 ALLOWED_IMPORTS.update(['ctypes', 'ctypes.wintypes', 'msvcrt', 'time',
17 unmodified lines
modified:CHANGES+1 added
9 unmodified lines
1011- Make `click.progressbar` work with `codecs.open` files. See #637.12- Fix bug in bash completion with nested subcommands. See #639.13- Fix test runner not saving caller env correctly. See #644.14- Fix handling of SIGPIPE. See #6261516Version 6.617-----------18
332 unmodified lines