aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2021-05-03 22:17:58 +0200
committerWolfgang Müller2021-05-03 22:34:59 +0200
commita7a90bded8023df34e1f63311cb786072a9a2037 (patch)
treecedcb74368169a880d776b84731473fd58333030
parenta096cc81cfa65a166127a3a7e0942c277fbb66b8 (diff)
downloadquarg-a7a90bded8023df34e1f63311cb786072a9a2037.tar.gz
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.
Diffstat (limited to '')
-rw-r--r--quarg/main.py4
1 files changed, 4 insertions, 0 deletions
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)