Author: ianb
Date: 2004-09-27 13:57:02 -0400 (Mon, 27 Sep 2004)
New Revision: 229
Modified:
trunk/SQLObject/sqlobject/dbconnection.py
Log:
Explicitly close all database connections (SF patch 1033807, though not
directly applied).
Modified: trunk/SQLObject/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
--- trunk/SQLObject/sqlobject/dbconnection.py 2004-09-27 17:34:05 UTC (re=
v 228)
+++ trunk/SQLObject/sqlobject/dbconnection.py 2004-09-27 17:57:02 UTC (re=
v 229)
@@ -14,11 +14,17 @@
from joins import sorter
from converters import sqlrepr
import urllib
+import weakref
=20
warnings.filterwarnings("ignore", "DB-API extension cursor.lastrowid use=
d")
=20
_connections =3D {}
=20
+def _closeConnection(ref):
+ conn =3D ref()
+ if conn is not None:
+ conn.close()
+
class DBConnection:
=20
def __init__(self, name=3DNone, debug=3DFalse, debugOutput=3DFalse,
@@ -35,6 +41,7 @@
self._connectionCount =3D 1
self.autoCommit =3D autoCommit
registerConnectionInstance(self)
+ atexit.register(_closeConnection, weakref.ref(self))
=20
def uri(self):
auth =3D self.user or ''
@@ -439,6 +446,17 @@
def sqlrepr(self, v):
return sqlrepr(v, self.dbName)
=20
+ def __del__(self):
+ self.close()
+
+ def close(self):
+ if self._pool:
+ for conn in self._pool:
+ try:
+ conn.close()
+ except self.module.Error:
+ pass
+
class Iteration(object):
=20
def __init__(self, dbconn, rawconn, select, keepConnection=3DFalse):
|