def _have_cancel_key(self): if self._cancel != ffi.NULL: tmp, self._cancel = self._cancel, ffi.NULL libpq.PQfreeCancel(tmp) self._cancel = libpq.PQgetCancel(self._pgconn) if self._cancel == ffi.NULL: raise exceptions.OperationalError("can't get cancellation key")
def _close(self): if self._closed == 1: return if self._cancel: libpq.PQfreeCancel(self._cancel) self._cancel = ffi.NULL if self._pgconn: libpq.PQfinish(self._pgconn) self._pgconn = None self._closed = 1