MiscUtils.DBPool | index /usr/local/share/webware/MiscUtils/DBPool.py

`DBPool.py
Implements a pool of cached connections to a database for any DB-API 2
compliant database module. This should result in a speedup for persistent
applications like Webware. The pool of connections is threadsafe regardless
of whether the used DB-API 2 general has a threadsafety of 1 or 2.
For more information on the DB API, see:
http://www.python.org/topics/database/DatabaseAPI-2.0.html
The idea behind DBPool is that it's completely seamless, so once you have
established your connection, use it just as you would any other DB-API 2
compliant module. For example:
import pgdb # import used DB-API 2 module
from MiscUtils.DBPool import DBPool
dbpool = DBPool(pgdb, 5, host=..., database=..., user=..., ...)
db = dbpool.connection()
Now use "db" exactly as if it were a pgdb connection. It's really
just a proxy class.
db.close() will return the connection to the pool, not actually
close it. This is so your existing code works nicely.
DBPool is actually intended to be a demonstration of concept not to be
used in a productive environment. It is really a very simple solution with
several drawbacks. For instance, pooled database connections which have
become invalid are not automatically recovered. For a more sophisticated
solution, please have a look at the DBUtils package:
http://www.webwareforpython.org/DBUtils
CREDIT
* Contributed by Dan Green.
* Thread safety bug found by Tom Schwaller.
* Fixes by Geoff Talvola (thread safety in _threadsafe_get_connection()).
* Clean up by Chuck Esterbrook.
* Fix unthreadsafe functions which were leaking, Jay Love.
* Eli Green's webware-discuss comments were lifted for additional docs.
* Coding and comment clean-up by Christoph Zwerschke.`

Modules
`` |  |
threading |  |  |

Classes
`` |  | DBPool PooledConnection exceptions.Exception(exceptions.BaseException) DBPoolError NotSupportedError
class DBPool
`` |  | Methods defined here: __init__(self, dbapi, maxconnections, *args, **kwargs) `Set up the database connection pool. dbapi: the DB-API 2 compliant module you want to use maxconnections: the number of connections cached in the pool args, kwargs: the parameters that shall be used to establish the database connections using connect()`
class DBPoolError(exceptions.Exception)
`` |  | Method resolution order: DBPoolError exceptions.Exception exceptions.BaseException __builtin__.object Data descriptors defined here: __weakref__ `list of weak references to the object (if defined)` Methods inherited from exceptions.Exception: __init__(...) `x.__init__(...) initializes x; see x.__class__.__doc__ for signature` Data and other attributes inherited from exceptions.Exception: __new__ = <built-in method __new__ of type object at 0x8118bc0> `T.__new__(S, ...) -> a new object with type S, a subtype of T` Methods inherited from exceptions.BaseException: __delattr__(...) `x.__delattr__('name') <==> del x.name` __getattribute__(...) `x.__getattribute__('name') <==> x.name` __getitem__(...) `x.__getitem__(y) <==> x[y]` __getslice__(...) `x.__getslice__(i, j) <==> x[i:j] Use of negative indices is not supported.` __reduce__(...) __repr__(...) `x.__repr__() <==> repr(x)` __setattr__(...) `x.__setattr__('name', value) <==> x.name = value` __setstate__(...) __str__(...) `x.__str__() <==> str(x)` Data descriptors inherited from exceptions.BaseException: __dict__ args message `exception message`
class NotSupportedError(DBPoolError)
`` |  | Method resolution order: NotSupportedError DBPoolError exceptions.Exception exceptions.BaseException __builtin__.object Data descriptors inherited from DBPoolError: __weakref__ `list of weak references to the object (if defined)` Methods inherited from exceptions.Exception: __init__(...) `x.__init__(...) initializes x; see x.__class__.__doc__ for signature` Data and other attributes inherited from exceptions.Exception: __new__ = <built-in method __new__ of type object at 0x8118bc0> `T.__new__(S, ...) -> a new object with type S, a subtype of T` Methods inherited from exceptions.BaseException: __delattr__(...) `x.__delattr__('name') <==> del x.name` __getattribute__(...) `x.__getattribute__('name') <==> x.name` __getitem__(...) `x.__getitem__(y) <==> x[y]` __getslice__(...) `x.__getslice__(i, j) <==> x[i:j] Use of negative indices is not supported.` __reduce__(...) __repr__(...) `x.__repr__() <==> repr(x)` __setattr__(...) `x.__setattr__('name', value) <==> x.name = value` __setstate__(...) __str__(...) `x.__str__() <==> str(x)` Data descriptors inherited from exceptions.BaseException: __dict__ args message `exception message`
class PooledConnection
`` | `A wrapper for database connections to help with DBPool. You don't normally deal with this class directly, but use DBPool to get new connections.`
| Methods defined here: __del__(self) __getattr__(self, name) __init__(self, pool, con) close(self) `Close the pooled connection.`