From eca33a3bf6731cd651dd89aa2bc38956dc852f58 Mon Sep 17 00:00:00 2001 From: Chris Berkhout Date: Thu, 27 May 2021 18:47:42 +0200 Subject: [PATCH] Handle BrokenPipeError gracefully. --- src/pricehist/cli.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pricehist/cli.py b/src/pricehist/cli.py index fb0e3a4..164c7fe 100644 --- a/src/pricehist/cli.py +++ b/src/pricehist/cli.py @@ -21,7 +21,7 @@ def cli(args=None): elif args.debug: logging.getLogger().setLevel(logging.DEBUG) - logging.debug(f"pricehist started at {start_time}") + logging.debug(f"Started pricehist run at {start_time}.") if args.version: cmd_version() @@ -34,7 +34,7 @@ def cli(args=None): else: parser.print_help() - logging.debug(f"pricehist finished at {datetime.now()}") + logging.debug(f"Finished pricehist run at {datetime.now()}.") def cmd_version(): @@ -121,7 +121,10 @@ def cmd_fetch(args): datesep=if_not_none(args.formatdatesep, default.datesep), ) - print(output.format(series, source, fmt=fmt), end="") + try: + print(output.format(series, source, fmt=fmt), end="") + except BrokenPipeError: + logging.debug("The output pipe was closed early.") def build_parser():