]> gitweb.michael.orlitzky.com - djbdns-logparse.git/blobdiff - djbdns/io.py
djbdns/io.py: handle BrokenPipeError in parse_logfile().
[djbdns-logparse.git] / djbdns / io.py
index 7c70bab3debcf2b78ad43e18146488740cdf1c4e..1d68fac428ce534652ad50e81c56869121c33a0e 100644 (file)
@@ -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()