We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
head
1 parent 49090c0 commit 7010fcfCopy full SHA for 7010fcf
lib/fdiff/__main__.py
@@ -12,7 +12,19 @@
12
13
14
def main(): # pragma: no cover
15
- run(sys.argv[1:])
+ # try/except block rationale:
16
+ # handles "premature" socket closure exception that is
17
+ # raised by Python when stdout is piped to tools like
18
+ # the `head` executable and socket is closed early
19
+ # see: https://docs.python.org/3/library/signal.html#note-on-sigpipe
20
+ try:
21
+ run(sys.argv[1:])
22
+ except BrokenPipeError:
23
+ # Python flushes standard streams on exit; redirect remaining output
24
+ # to devnull to avoid another BrokenPipeError at shutdown
25
+ devnull = os.open(os.devnull, os.O_WRONLY)
26
+ os.dup2(devnull, sys.stdout.fileno())
27
+ sys.exit(0)
28
29
30
def run(argv):
0 commit comments