[z3-checkins] r41771 - in z3/sqlos/trunk/src/sqlos: . ftests
kobold at codespeak.net
kobold at codespeak.net
Sun Apr 1 19:24:56 CEST 2007
Author: kobold
Date: Sun Apr 1 19:24:55 2007
New Revision: 41771
Modified:
z3/sqlos/trunk/src/sqlos/connection.py
z3/sqlos/trunk/src/sqlos/ftests/localutilities.txt
Log:
Let's try to fix the new code: it didn't work with multiple threads.
Modified: z3/sqlos/trunk/src/sqlos/connection.py
==============================================================================
--- z3/sqlos/trunk/src/sqlos/connection.py (original)
+++ z3/sqlos/trunk/src/sqlos/connection.py Sun Apr 1 19:24:55 2007
@@ -21,6 +21,7 @@
"""
__metaclass__ = type
+import thread
import warnings
from zope.app import zapi
@@ -66,58 +67,41 @@
# This code was heavily based on ZODB.Transaction
connCache = {}
-try:
- import thread
-except:
- def getConnection(context, name):
- global connCache
- if not connCache.get(name):
- newconn = zapi.queryUtility(IZopeDatabaseAdapter, name,
- default=None,
- context=context)
- if newconn is None:
- warnings.warn("Couldn't find a rdb connection by the "
- "name %s. Please verify your setup." % name,
- SQLOSWarning, 3)
- connCache[name] = IZopeSQLConnection(newconn())
- return connCache[name]
-
- def releaseConnection(name):
- global connCache
- if connCache.has_key(name):
- connCache[name].close()
- del connCache[name]
-else:
- def getConnection(context, name):
- global connCache
- tid = thread.get_ident()
- key = (tid, name)
- if not connCache.get(key):
- newconn = zapi.queryUtility(IZopeDatabaseAdapter, name,
- default=None,
- context=context)
- if newconn is None:
- warnings.warn("Couldn't find a rdb connection by the "
- "name %s. Please verify your setup." % name,
- SQLOSWarning, 3)
- conn = IZopeSQLConnection(newconn())
- if conn.supportTransactions:
- connCache[key] = conn.transaction()
- else: # At least MySQL does not support transactions
- connCache[key] = conn
-
- return connCache[key]
-
- def releaseConnection(name):
- global connCache
- tid = thread.get_ident()
- key = (tid, name)
- if connCache.has_key(key):
- connCache[key].close()
- del connCache[key]
+
+def getConnection(context, name):
+ global connCache
+ tid = thread.get_ident()
+ key = (tid, name)
+ if not connCache.get(key):
+ newconn = zapi.queryUtility(IZopeDatabaseAdapter, name,
+ default=None,
+ context=context)
+ if newconn is None:
+ warnings.warn("Couldn't find a rdb connection by the "
+ "name %s. Please verify your setup." % name,
+ SQLOSWarning, 3)
+ conn = IZopeSQLConnection(newconn())
+ if conn.supportTransactions:
+ connCache[key] = conn.transaction()
+ else: # At least MySQL does not support transactions
+ connCache[key] = conn
+
+ return connCache[key]
+
+
+def releaseConnection(name):
+ global connCache
+ tid = thread.get_ident()
+ key = (tid, name)
+ if connCache.has_key(key):
+ connCache[key].close()
+ del connCache[key]
def clearCacheSubscriber(*args):
"""A subscriber to clear the connection cache at site boundaries."""
- for connection in connCache.values():
- connection.cache.clear()
+ tid = thread.get_ident()
+ for name in connCache.keys():
+ if name[0] != tid:
+ continue
+ connCache[name].cache.clear()
Modified: z3/sqlos/trunk/src/sqlos/ftests/localutilities.txt
==============================================================================
--- z3/sqlos/trunk/src/sqlos/ftests/localutilities.txt (original)
+++ z3/sqlos/trunk/src/sqlos/ftests/localutilities.txt Sun Apr 1 19:24:55 2007
@@ -41,9 +41,6 @@
>>> localUtility is dbAdapter
True
- >>> localUtility is dbAdapter
- True
-
Ok. Now we have a site in root/testsite with a registered sqlite adapter. We
make sure that our localUtility is not identical to the global sqlite utility
that has been registered through ftesting.zcml.
More information about the z3-checkins
mailing list