summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Williams <rdw@lindenlab.com>2007-07-27 22:08:25 +0000
committerRyan Williams <rdw@lindenlab.com>2007-07-27 22:08:25 +0000
commit24c0e384facb659775ecd5c2f9becc3694f80289 (patch)
tree4303be2d6d716850ae7e93843205182e76906128
parente27e86e0334dc847687a557d0891c6ca91bb7de9 (diff)
New mysql connection pool for Python, plus unit tests that verify that it's actually non-blocking. Some additional behavior in saranwrap, with tests that pass. Reviewd by Donovan.
-rw-r--r--indra/lib/python/indra/ipc/mysql_pool.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/indra/lib/python/indra/ipc/mysql_pool.py b/indra/lib/python/indra/ipc/mysql_pool.py
new file mode 100644
index 0000000000..2bbb60ba0b
--- /dev/null
+++ b/indra/lib/python/indra/ipc/mysql_pool.py
@@ -0,0 +1,37 @@
+"""\
+@file mysql_pool.py
+@brief Uses saranwrap to implement a pool of nonblocking database connections to a mysql server.
+
+Copyright (c) 2007, Linden Research, Inc.
+$License$
+"""
+
+import os
+
+from eventlet.pools import Pool, DeadProcess
+from indra.ipc import saranwrap
+
+import MySQLdb
+
+class ConnectionPool(Pool):
+ """A pool which gives out saranwrapped MySQLdb connections from a pool
+ """
+ def __init__(self, min_size = 0, max_size = 4, *args, **kwargs):
+ self._args = args
+ self._kwargs = kwargs
+ Pool.__init__(self, min_size, max_size)
+
+ def create(self):
+ return saranwrap.wrap(MySQLdb).connect(*self._args, **self._kwargs)
+
+ def put(self, conn):
+ # poke the process to see if it's dead or None
+ try:
+ status = saranwrap.status(conn)
+ except (AttributeError, DeadProcess), e:
+ conn = self.create()
+
+ if conn:
+ Pool.put(self, conn)
+ else:
+ self.current_size -= 1