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

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Thu Sep 23 10:36:08 EDT 2010


Author: justi9
Date: 2010-09-23 10:36:07 -0400 (Thu, 23 Sep 2010)
New Revision: 4335

Modified:
   mgmt/newdata/cumin/python/cumin/database.py
Log:
Replace closed database connections on demand

Modified: mgmt/newdata/cumin/python/cumin/database.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/database.py	2010-09-23 13:49:25 UTC (rev 4334)
+++ mgmt/newdata/cumin/python/cumin/database.py	2010-09-23 14:36:07 UTC (rev 4335)
@@ -20,11 +20,14 @@
         #m = re.match(r"^([^:]+)://([^@]+)@([^/]+)/(.+)$", self.uri)
 
     def get_connection(self):
-        if not hasattr(self.thread_local, "connection"):
-            self.thread_local.connection = psycopg2.connect(self.dsn)
+        conn = getattr(self.thread_local, "connection", None)
 
-        return self.thread_local.connection
+        if not conn or conn.closed:
+            conn = psycopg2.connect(self.dsn)
+            setattr(self.thread_local, "connection", conn)
 
+        return conn
+
     def __repr__(self):
         return self.__class__.__name__
 



More information about the rhmessaging-commits mailing list