summaryrefslogtreecommitdiff
path: root/lib/extras.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2015-10-01 15:26:13 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2015-10-01 15:26:13 +0100
commitf635547ec690cc76b02da8e22772d41008fcc46e (patch)
treee0ed1040565cae6c543cf39f069ad3ff3daa6fda /lib/extras.py
parent9e6c3322d8640bca7007a222973d87d8ea60057c (diff)
downloadpsycopg2-f635547ec690cc76b02da8e22772d41008fcc46e.tar.gz
The wait_select callback can cancel a query using Ctrl-C
Fixes #333.
Diffstat (limited to 'lib/extras.py')
-rw-r--r--lib/extras.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/extras.py b/lib/extras.py
index c9f1cbc..2713d6f 100644
--- a/lib/extras.py
+++ b/lib/extras.py
@@ -575,15 +575,20 @@ def wait_select(conn):
from psycopg2.extensions import POLL_OK, POLL_READ, POLL_WRITE
while 1:
- state = conn.poll()
- if state == POLL_OK:
- break
- elif state == POLL_READ:
- select.select([conn.fileno()], [], [])
- elif state == POLL_WRITE:
- select.select([], [conn.fileno()], [])
- else:
- raise conn.OperationalError("bad state from poll: %s" % state)
+ try:
+ state = conn.poll()
+ if state == POLL_OK:
+ break
+ elif state == POLL_READ:
+ select.select([conn.fileno()], [], [])
+ elif state == POLL_WRITE:
+ select.select([], [conn.fileno()], [])
+ else:
+ raise conn.OperationalError("bad state from poll: %s" % state)
+ except KeyboardInterrupt:
+ conn.cancel()
+ # the loop will be broken by a server error
+ continue
def _solve_conn_curs(conn_or_curs):