143
140
self->closed = 1;
145
142
/* execute a forced rollback on the connection (but don't check the
146
result, we're going to close the pq connection anyway */
147
if (self->pgconn) pq_abort(self);
149
/* orphans all the children cursors but do NOT destroy them (note that we
150
need to lock the connection before orphaning a cursor: we don't want to
151
remove a connection from a cursor executing a DB operation */
152
pthread_mutex_unlock(&self->lock);
153
Py_END_ALLOW_THREADS;
155
pthread_mutex_lock(&self->lock);
156
len = PyList_Size(self->cursors);
157
Dprintf("conn_close: ophaning %d cursors", len);
158
for (i = len-1; i >= 0; i--) {
159
t = PySequence_GetItem(self->cursors, i);
160
Dprintf("conn close: cursor at %p: refcnt = %d", t, t->ob_refcnt);
161
PySequence_DelItem(self->cursors, i);
162
((cursorObject *)t)->conn = NULL; /* orphaned */
163
Dprintf("conn_close: -> new refcnt = %d", t->ob_refcnt);
165
pthread_mutex_unlock(&self->lock);
167
/* now that all cursors have been orphaned (they can't operate on the
168
database anymore) we can shut down the connection */
143
result, we're going to close the pq connection anyway */
169
144
if (self->pgconn) {
170
146
PQfinish(self->pgconn);
171
147
Dprintf("conn_close: PQfinish called");
172
148
self->pgconn = NULL;
151
pthread_mutex_unlock(&self->lock);
152
Py_END_ALLOW_THREADS;
176
156
/* conn_commit - commit on a connection */