Skip to content

Commit 65af3fa

Browse files
authored
Merge pull request #8 from polm/fix/sigpipe
Handle sigpipe
2 parents f981501 + bb25f0a commit 65af3fa

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

gh-repo-list

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"""List all repositories."""
33
import argparse
44
import json
5+
import os
56
import subprocess
7+
import sys
68
from dataclasses import dataclass
79
from pprint import pprint
810
# Use `typing.*` instead of `collections.abc` to support older Python versions.
@@ -20,8 +22,15 @@ def main():
2022
commands = list_commands()
2123
command = commands[args.type]
2224

23-
for output in command():
24-
print(output)
25+
try:
26+
for output in command():
27+
print(output)
28+
except BrokenPipeError:
29+
# see docs here:
30+
# https://docs.python.org/3/library/signal.html#note-on-sigpipe
31+
devnull = os.open(os.devnull, os.O_WRONLY)
32+
os.dup2(devnull, sys.stdout.fileno())
33+
sys.exit(1) # Python exits with error code 1 on EPIPE
2534

2635

2736
@dataclass

0 commit comments

Comments
 (0)