Skip to content
Snippets Groups Projects
Commit 2553cc30 authored by Lars Bilke's avatar Lars Bilke
Browse files

Merge branch 'fix-py-signal-handling' into 'master'

Fix Python broken pipe signal handling

See merge request ogs/ogs!5062
parents 9fdef1ae 981ea88f
No related branches found
No related tags found
No related merge requests found
......@@ -8,12 +8,9 @@ import sys
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 (.*)[.]$")
......@@ -274,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
......@@ -317,11 +318,18 @@ if __name__ == "__main__":
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)
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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment