[rhmessaging-commits] rhmessaging commits: r4314 - mgmt/newdata/cumin/python/cumin.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Tue Sep 21 06:06:35 EDT 2010


Author: justi9
Date: 2010-09-21 06:06:35 -0400 (Tue, 21 Sep 2010)
New Revision: 4314

Modified:
   mgmt/newdata/cumin/python/cumin/database.py
Log:
Use a thread local to reuse database connections

Modified: mgmt/newdata/cumin/python/cumin/database.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/database.py	2010-09-20 21:04:34 UTC (rev 4313)
+++ mgmt/newdata/cumin/python/cumin/database.py	2010-09-21 10:06:35 UTC (rev 4314)
@@ -1,5 +1,6 @@
 import psycopg2
 import re
+import threading
 
 from util import *
 
@@ -11,6 +12,7 @@
         self.dsn = dsn
 
         self.connection_args = dict()
+        self.thread_local = threading.local()
 
     def init(self):
         log.info("Initializing %s", self)
@@ -18,8 +20,11 @@
         #m = re.match(r"^([^:]+)://([^@]+)@([^/]+)/(.+)$", self.uri)
 
     def get_connection(self):
-        return psycopg2.connect(self.dsn)
+        if not hasattr(self.thread_local, "connection"):
+            self.thread_local.connection = psycopg2.connect(self.dsn)
 
+        return self.thread_local.connection
+
     def __repr__(self):
         return self.__class__.__name__
 



More information about the rhmessaging-commits mailing list