[SQL-CVS] r83 - branches/SQLObject/0.5/SQLObject
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2004-03-31 06:43:27
|
Author: ianb Date: 2004-03-30 21:48:02 -0500 (Tue, 30 Mar 2004) New Revision: 83 Modified: branches/SQLObject/0.5/SQLObject/DBConnection.py Log: Fixed another (blech) threading issue with iterators, where a=20 connection could be returned to the pool multiple times, and then be fetched from the pool by different threads. Modified: branches/SQLObject/0.5/SQLObject/DBConnection.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/SQLObject/0.5/SQLObject/DBConnection.py 2004-03-31 02:47:19 = UTC (rev 82) +++ branches/SQLObject/0.5/SQLObject/DBConnection.py 2004-03-31 02:48:02 = UTC (rev 83) @@ -105,7 +105,11 @@ self.printDebug(conn, 'auto', 'ROLLBACK') conn.rollback() if self._pool is not None: - self._pool.append(conn) + if conn not in self._pool: + # @@: We can get duplicate releasing of connections with + # the __del__ in Iteration (unfortunately, not sure why + # it happens) + self._pool.append(conn) =20 def printDebug(self, conn, s, name, type=3D'query'): if type =3D=3D 'query': @@ -363,8 +367,7 @@ def next(self): result =3D self.cursor.fetchone() if result is None: - if not self.keepConnection: - self.dbconn.releaseConnection(self.rawconn) + self._cleanup() raise StopIteration if self.select.ops.get('lazyColumns', 0): obj =3D self.select.sourceClass(result[0], connection=3Dself= .dbconn) @@ -373,10 +376,18 @@ obj =3D self.select.sourceClass(result[0], selectResults=3Dr= esult[1:], connection=3Dself.dbconn) return obj =20 - def __del__(self): + def _cleanup(self): + if self.query is None: + # already cleaned up + return + self.query =3D None if not self.keepConnection: self.dbconn.releaseConnection(self.rawconn) + self.dbconn =3D self.rawconn =3D self.select =3D self.cursor =3D= None =20 + def __del__(self): + self._cleanup() + class Transaction(object): =20 def __init__(self, dbConnection): |