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())