Skip to content

Commit

Permalink
[scr] handle broken pipe error properly
Browse files Browse the repository at this point in the history
  • Loading branch information
chleh committed Aug 6, 2024
1 parent 9fdef1a commit 4448a2c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Applications/Python/ogs/dev/ogs_log_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
from collections import defaultdict
from decimal import ROUND_DOWN, ROUND_UP, Decimal
from pathlib import Path
from signal import SIG_DFL, SIGPIPE, signal

import pandas as pd

signal(SIGPIPE, SIG_DFL)

logger = logging.getLogger(__name__)

re_prj_file = re.compile("info: Reading project file (.*)[.]$")
Expand Down Expand Up @@ -324,4 +321,11 @@ def run(log_files_dirs, xml_out_dir, verbose):
ch.setFormatter(formatter)
logger.addHandler(ch)

run(args.log_files_dirs, snippet_out, args.verbose)
# suppress error message from Python interpreter, e.g., if a command
# pipeline exits early, see
# https://docs.python.org/3/library/signal.html#note-on-sigpipe
try:
run(args.log_files_dirs, snippet_out, args.verbose)
except BrokenPipeError:
devnull = os.open(os.devnull, os.O_WRONLY)
os.dup2(devnull, sys.stdout.fileno())

0 comments on commit 4448a2c

Please sign in to comment.