mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
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:
parent
76815f1e92
commit
2611d62283
|
@ -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. */
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user