diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-03-05 02:47:52 +0000 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-03-05 02:47:52 +0000 |
| commit | 37aa62ca52149360331e54740a2f70567343710e (patch) | |
| tree | 8e1828649c9cdb330635445646e0528fd4586b2b /psycopg | |
| parent | b97599166ec218b474f45e9a81ac7f4d58f63b71 (diff) | |
| parent | 84f2a370f6fc749aeb90628a0d0bdcf7f4b27048 (diff) | |
| download | psycopg2-37aa62ca52149360331e54740a2f70567343710e.tar.gz | |
Merge branch 'close-idempotent' into devel
Diffstat (limited to 'psycopg')
| -rw-r--r-- | psycopg/connection_int.c | 11 | ||||
| -rw-r--r-- | psycopg/connection_type.c | 2 | ||||
| -rw-r--r-- | psycopg/cursor_type.c | 6 |
3 files changed, 12 insertions, 7 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 7046513..2395c00 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -906,6 +906,10 @@ conn_poll(connectionObject *self) void conn_close(connectionObject *self) { + if (self->closed) { + return; + } + /* sets this connection as closed even for other threads; also note that we need to check the value of pgconn, because we get called even when the connection fails! */ @@ -922,14 +926,13 @@ conn_close(connectionObject *self) * closed only in status CONN_STATUS_READY. */ - if (self->closed == 0) - self->closed = 1; + self->closed = 1; if (self->pgconn) { PQfinish(self->pgconn); - PQfreeCancel(self->cancel); - Dprintf("conn_close: PQfinish called"); self->pgconn = NULL; + Dprintf("conn_close: PQfinish called"); + PQfreeCancel(self->cancel); self->cancel = NULL; } diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 693de3c..09ced62 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -122,8 +122,6 @@ psyco_conn_cursor(connectionObject *self, PyObject *args, PyObject *keywds) static PyObject * psyco_conn_close(connectionObject *self, PyObject *args) { - EXC_IF_CONN_CLOSED(self); - Dprintf("psyco_conn_close: closing connection at %p", self); conn_close(self); Dprintf("psyco_conn_close: connection at %p closed", self); diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index bb9db69..4de0163 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -52,9 +52,12 @@ extern PyObject *pyPsycopgTzFixedOffsetTimezone; static PyObject * psyco_curs_close(cursorObject *self, PyObject *args) { - EXC_IF_CURS_CLOSED(self); EXC_IF_ASYNC_IN_PROGRESS(self, close); + if (self->closed) { + goto exit; + } + if (self->name != NULL) { char buffer[128]; @@ -66,6 +69,7 @@ psyco_curs_close(cursorObject *self, PyObject *args) self->closed = 1; Dprintf("psyco_curs_close: cursor at %p closed", self); +exit: Py_INCREF(Py_None); return Py_None; } |
