Get the result from the connection after the green panic

Otherwise the connection won't be usable in case we manage
to put it back on track (libpq reports "another command is
already in progress")
This commit is contained in:
Daniele Varrazzo 2012-10-06 01:45:24 +01:00
parent 6b6aded90b
commit 7632e1ae46
2 changed files with 16 additions and 1 deletions

View File

@ -202,6 +202,7 @@ end:
static void
psyco_panic_cancel(connectionObject *conn)
{
PGresult *res;
PyObject *etype, *evalue, *etb;
char errbuf[256];
@ -229,6 +230,12 @@ psyco_panic_cancel(connectionObject *conn)
goto exit;
}
/* we must clear the result or we get "another command is already in
* progress" */
if (NULL != (res = pq_get_last_result(conn))) {
PQclear(res);
}
exit:
/* restore the exception. If no exception was set at function begin, don't
* clobber one that may have been set here. */

View File

@ -42,7 +42,15 @@ signal.signal(signal.SIGHUP, handler)
conn = psycopg2.connect(DSN)
curs = conn.cursor()
print "PID", os.getpid()
curs.execute("select pg_sleep(1000)")
try:
curs.execute("select pg_sleep(1000)")
except BaseException, e:
print "got exception:", e.__class__.__name__, e
conn.rollback()
curs.execute("select 1")
print curs.fetchone()
# You can unplug the network cable etc. here.
# Kill -HUP will raise an exception in the callback.