Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handles the BrokenPipeError #101

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions trlc/trlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
# You should have received a copy of the GNU General Public License
# along with TRLC. If not, see <https://www.gnu.org/licenses/>.

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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Loading