From f67f0f93e1c90eb778a51016c9777c9f7dae7839 Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Tue, 4 May 2021 21:09:38 +0200 Subject: main: Handle BrokenPipeError cleanly Whilst not recommended, quarg may happen to be used in conjunction with head(1), tail(1), or any other program that will send SIGPIPE. This commit makes sure that we close the database connection properly if we receive that signal. --- quarg/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quarg/main.py b/quarg/main.py index 29138e3..5e0aaf8 100644 --- a/quarg/main.py +++ b/quarg/main.py @@ -144,7 +144,7 @@ def main(): print(formatter.format_from(row)) except exc.SQLAlchemyError as err: errx(err) - except KeyboardInterrupt: + except (KeyboardInterrupt, BrokenPipeError): session.rollback() session.close() sys.exit(1) -- cgit v1.2.3-2-gb3c3