From 4448a2cdc6cec1ab4b19d9189fdae926d4c09014 Mon Sep 17 00:00:00 2001 From: Christoph Lehmann Date: Tue, 6 Aug 2024 08:07:20 +0200 Subject: [PATCH 1/3] [scr] handle broken pipe error properly --- Applications/Python/ogs/dev/ogs_log_summary.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Applications/Python/ogs/dev/ogs_log_summary.py b/Applications/Python/ogs/dev/ogs_log_summary.py index 5e6153391e7..3aa4e8c916f 100755 --- a/Applications/Python/ogs/dev/ogs_log_summary.py +++ b/Applications/Python/ogs/dev/ogs_log_summary.py @@ -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 (.*)[.]$") @@ -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()) From 20b7299a7ece5d576cc35df530cf19e3d449c355 Mon Sep 17 00:00:00 2001 From: Christoph Lehmann Date: Tue, 6 Aug 2024 08:09:51 +0200 Subject: [PATCH 2/3] [scr] Do not print debug output --- Applications/Python/ogs/dev/ogs_log_summary.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Applications/Python/ogs/dev/ogs_log_summary.py b/Applications/Python/ogs/dev/ogs_log_summary.py index 3aa4e8c916f..8297452cb1f 100755 --- a/Applications/Python/ogs/dev/ogs_log_summary.py +++ b/Applications/Python/ogs/dev/ogs_log_summary.py @@ -314,9 +314,9 @@ def run(log_files_dirs, xml_out_dir, verbose): if snippet_out is not None: assert snippet_out.is_dir() - logger.setLevel(logging.DEBUG) + logger.setLevel(logging.INFO) ch = logging.StreamHandler() - ch.setLevel(logging.DEBUG) + ch.setLevel(logging.INFO) formatter = logging.Formatter("[%(levelname)s] %(message)s") ch.setFormatter(formatter) logger.addHandler(ch) From 981ea88fa8af284306e0d1e1f7aed0525b2e1c0a Mon Sep 17 00:00:00 2001 From: Christoph Lehmann Date: Tue, 6 Aug 2024 08:12:58 +0200 Subject: [PATCH 3/3] [scr] Only print blank line as separator if reasonable --- Applications/Python/ogs/dev/ogs_log_summary.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Applications/Python/ogs/dev/ogs_log_summary.py b/Applications/Python/ogs/dev/ogs_log_summary.py index 8297452cb1f..3b442fa5de5 100755 --- a/Applications/Python/ogs/dev/ogs_log_summary.py +++ b/Applications/Python/ogs/dev/ogs_log_summary.py @@ -271,9 +271,13 @@ def aggregate_log_files(log_files_dirs): def run(log_files_dirs, xml_out_dir, verbose): map_prj_file_to_agg_vtkdiff_stats = aggregate_log_files(log_files_dirs) - for prj_file, df_vtkdiff_max in map_prj_file_to_agg_vtkdiff_stats.items(): + for i, (prj_file, df_vtkdiff_max) in enumerate( + map_prj_file_to_agg_vtkdiff_stats.items() + ): if verbose: - print(f"\n###### {prj_file}\n") + if i != 0: + print() # blank line as a separator + print(f"###### {prj_file}\n") df_vtkdiff_max = round_up_2_digits(df_vtkdiff_max) # noqa: PLW2901