]> git.ipfire.org Git - thirdparty/psycopg.git/commit
fix: Cancel query on Ctrl-C
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 22 Feb 2022 03:02:13 +0000 (04:02 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 2 Mar 2022 01:55:26 +0000 (01:55 +0000)
commit0269012e2e2b624196b3ebfb0fa13a2bd22201e1
treeb7e9901b3a14efad769d66efdcd755727128839e
parenta73afd2468bc5d9257be2e933ad6d8b036b70114
fix: Cancel query on Ctrl-C

On KeyboardInterrupt, send a cancel to the server and keep waiting for
the result of the cancel, which is expected to raise a QueryCanceled,
then re-raise KeyboardInterrupt.

Before this, the connection was left in ACTIVE state, so it couldn't be rolled
back.

Only fixed on sync connections. Left a failing test for async
connections; the test fails with an output from the script such as:

    error ignored in rollback on <psycopg.AsyncConnection [ACTIVE] ...>:
    sending query failed: another command is already in progress
    Traceback (most recent call last):
      File "<string>", line 27, in <module>
      File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
        return loop.run_until_complete(main)
      File "/usr/lib/python3.8/asyncio/base_events.py", line 603, in run_until_complete
        self.run_forever()
      File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
        self._run_once()
      File "/usr/lib/python3.8/asyncio/base_events.py", line 1823, in _run_once
        event_list = self._selector.select(timeout)
      File "/usr/lib/python3.8/selectors.py", line 468, in select
        fd_event_list = self._selector.poll(timeout, max_ev)
    KeyboardInterrupt

And the except branch in `AsyncConnection.wait()` is not reached.

See #231
docs/news.rst
psycopg/psycopg/connection.py
psycopg/psycopg/connection_async.py
tests/test_concurrency.py
tests/test_concurrency_async.py