Skip to content

Commit a84c728

Browse files
committed
more information and care on KeyboardInterrupt
mycli is already _much_ better at cancelling queries on KeyboardInterrupt, compared to the vendor client. But not perfect -- and sometimes the result is an unfortunate runaway query. Here we: * catch the case that "ok" is not in the status string, and emit a warning in red. Previously we only caught Exceptions. * add an echo to the debugged path in which cancellation is skipped. * downgrade the routine cancellation message to blue and add the query id number. The first and second changes are intended to help the user notice the cases in which we fail to interrupt, and know that we failed. The third change is intended to help in unknown cases, in which we believe that we succeeded, but didn't interrupt.
1 parent ba24678 commit a84c728

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Features
55
--------
66

77
* Support SSL query parameters on DSNs.
8+
* More information and care on KeyboardInterrupt.
89

910
Internal
1011
--------

mycli/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,11 +774,15 @@ def one_iteration(text=None):
774774
status_str = str(status).lower()
775775
if status_str.find("ok") > -1:
776776
logger.debug("cancelled query, connection id: %r, sql: %r", connection_id_to_kill, text)
777-
self.echo("cancelled query", err=True, fg="red")
777+
self.echo(f"Cancelled query id: {connection_id_to_kill}", err=True, fg="blue")
778+
else:
779+
logger.debug("Failed to confirm query cancellation, connection id: %r, sql: %r", connection_id_to_kill, text)
780+
self.echo(f"Failed to confirm query cancellation, id: {connection_id_to_kill}", err=True, fg="red")
778781
except Exception as e:
779782
self.echo("Encountered error while cancelling query: {}".format(e), err=True, fg="red")
780783
else:
781784
logger.debug("Did not get a connection id, skip cancelling query")
785+
self.echo("Did not get a connection id, skip cancelling query", err=True, fg="red")
782786
except NotImplementedError:
783787
self.echo("Not Yet Implemented.", fg="yellow")
784788
except OperationalError as e:

0 commit comments

Comments
 (0)