Skip to content

Commit 38457cc

Browse files
committed
prevent broken pipe error if the user pipes output to a process
1 parent ffec193 commit 38457cc

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

gitless/cli/helpers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def get_branch_or_use_upstream(branch_name, arg, repo):
7070

7171
def page(fp, repo):
7272
if not sys.stdout.isatty(): # we are being piped or redirected
73+
# Prevent Python from throwing exceptions on SIGPIPE
74+
from signal import signal, SIGPIPE, SIG_DFL
75+
signal(SIGPIPE, SIG_DFL)
7376
# memory-friendly way to output contents of file to stdout
7477
with open(fp, 'r') as f:
7578
shutil.copyfileobj(f, sys.stdout)

0 commit comments

Comments
 (0)