From a7a90bded8023df34e1f63311cb786072a9a2037 Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Mon, 3 May 2021 22:17:58 +0200 Subject: main: Handle user interrupts more nicely Users may want to cancel queries that are taking a long time. This commit ensures that the database is left in a clean state and that quarg exits immediately after closing the database connection. --- quarg/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/quarg/main.py b/quarg/main.py index 9532ba7..f21327d 100644 --- a/quarg/main.py +++ b/quarg/main.py @@ -144,6 +144,10 @@ def main(): print(formatter.format_from(row)) except exc.SQLAlchemyError as err: errx(err) + except KeyboardInterrupt: + session.rollback() + session.close() + sys.exit(1) print(f'Query returned {len(rows)} lines in {time:.4f} seconds.', file=sys.stderr) -- cgit v1.2.3-2-gb3c3