From 86b114ab8951b29f498cd0171c7e747abdf0d065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Kl=C3=B6ffel?= <145490354+christophkloeffel@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:35:46 +0200 Subject: [PATCH] ignores the BrokenPipeError (#101) fixes #94 --- trlc/trlc.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/trlc/trlc.py b/trlc/trlc.py index 4798b03..6c0db92 100644 --- a/trlc/trlc.py +++ b/trlc/trlc.py @@ -18,20 +18,19 @@ # You should have received a copy of the GNU General Public License # along with TRLC. If not, see . -import re -import os -import sys -import json import argparse +import json +import os +import re import subprocess +import sys from fractions import Fraction -from trlc import ast -from trlc import lint -from trlc.errors import TRLC_Error, Location, Message_Handler, Kind -from trlc.parser import Parser +from trlc import ast, lint +from trlc.errors import Kind, Location, Message_Handler, TRLC_Error from trlc.lexer import Token_Stream -from trlc.version import TRLC_VERSION, BUGS_URL +from trlc.parser import Parser +from trlc.version import BUGS_URL, TRLC_VERSION # pylint: disable=unused-import try: @@ -551,7 +550,7 @@ def process(self): return self.stab -def main(): +def trlc(): ap = argparse.ArgumentParser( prog="trlc", description="TRLC %s (Python reference implementation)" % TRLC_VERSION, @@ -821,5 +820,16 @@ def get_status(parser): return 1 +def main(): + try: + return trlc() + except BrokenPipeError: + # Python flushes standard streams on exit; redirect remaining output + # to devnull to avoid another BrokenPipeError at shutdown + devnull = os.open(os.devnull, os.O_WRONLY) + os.dup2(devnull, sys.stdout.fileno()) + return 141 + + if __name__ == "__main__": sys.exit(main())