From 4645a2edd7eeb0470d5796f4f15f02d23429288e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 20 Sep 2022 19:48:10 -0400 Subject: [PATCH] djbdns/io.py: handle BrokenPipeError in parse_logfile(). This avoids a (harmless) crash when the output of djbdns-logparse is piped to a process (such as head/tail) that closes the pipe before djbdns-logparse is done writing to it. --- djbdns/io.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/djbdns/io.py b/djbdns/io.py index 7c70bab..1d68fac 100644 --- a/djbdns/io.py +++ b/djbdns/io.py @@ -43,7 +43,13 @@ def parse_logfile(file : TextIO): if not friendly_line: friendly_line = line - print(friendly_line) + try: + print(friendly_line) + except BrokenPipeError: + # If our stdout is being piped to another process and if + # that process closes the pipe, this error will be raised + # the next time we try to write to stdout. + break # Ensure that the pipe gets closed. tai.communicate() -- 2.43.2