From 98207edf309c58198b6b1700776fc415a6bcac19 Mon Sep 17 00:00:00 2001 From: Jason Kirtland Date: Wed, 9 May 2007 22:39:50 +0000 Subject: - Connections can be detached from their pool, closing on dereference instead of returning to the pool for reuse --- lib/sqlalchemy/pool.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/pool.py') diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index 9a2cdad0e..6ad560e5b 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -260,7 +260,8 @@ class _ConnectionFairy(object): def invalidate(self, e=None): if self.connection is None: raise exceptions.InvalidRequestError("This connection is closed") - self._connection_record.invalidate(e=e) + if self._connection_record is not None: + self._connection_record.invalidate(e=e) self.connection = None self._cursors = None self._close() @@ -282,6 +283,12 @@ class _ConnectionFairy(object): self.__counter +=1 return self + def detach(self): + if self._connection_record is not None: + self._connection_record.connection = None + self._pool.do_return_conn(self._connection_record) + self._connection_record = None + def close_open_cursors(self): if self._cursors is not None: for c in list(self._cursors): @@ -307,6 +314,9 @@ class _ConnectionFairy(object): if self.connection is not None: try: self.connection.rollback() + # Immediately close detached instances + if self._connection_record is None: + self.connection.close() except Exception, e: if self._connection_record is not None: self._connection_record.invalidate(e=e) -- cgit v1.2.1