summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/pool.py
diff options
context:
space:
mode:
authorJason Kirtland <jek@discorporate.us>2008-04-04 19:07:30 +0000
committerJason Kirtland <jek@discorporate.us>2008-04-04 19:07:30 +0000
commitafd8431d4d6527d32d43f0a6c11d75ba2b0adcaf (patch)
tree88f13aaf756078b1eb7c10c5647a1885b9eaeac5 /lib/sqlalchemy/pool.py
parentde209ded31c3914d70e5372b0c49b6fd84639d48 (diff)
downloadsqlalchemy-afd8431d4d6527d32d43f0a6c11d75ba2b0adcaf.tar.gz
- Pool listeners may now be specified as a duck-type of PoolListener or a dict of callables, your choice.
Diffstat (limited to 'lib/sqlalchemy/pool.py')
-rw-r--r--lib/sqlalchemy/pool.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py
index 94d9127f0..71c0c82df 100644
--- a/lib/sqlalchemy/pool.py
+++ b/lib/sqlalchemy/pool.py
@@ -20,7 +20,7 @@ import weakref, time
from sqlalchemy import exceptions, logging
from sqlalchemy import queue as Queue
-from sqlalchemy.util import thread, threading, pickle
+from sqlalchemy.util import thread, threading, pickle, as_interface
proxies = {}
@@ -106,9 +106,10 @@ class Pool(object):
newly opened connection. Defaults to -1.
listeners
- A list of ``PoolListener``-like objects that receive events when
- DB-API connections are created, checked out and checked in to
- the pool.
+ A list of ``PoolListener``-like objects or dictionaries of callables
+ that receive events when DB-API connections are created, checked out and
+ checked in to the pool.
+
"""
def __init__(self, creator, recycle=-1, echo=None, use_threadlocal=True,
@@ -182,7 +183,16 @@ class Pool(object):
raise NotImplementedError()
def add_listener(self, listener):
- """Add a ``PoolListener``-like object to this pool."""
+ """Add a ``PoolListener``-like object to this pool.
+
+ ``listener`` may be an object that implements some or all of
+ PoolListener, or a dictionary of callables containing implementations
+ of some or all of the named methods in PoolListener.
+
+ """
+
+ listener = as_interface(
+ listener, methods=('connect', 'checkout', 'checkin'))
self.listeners.append(listener)
if hasattr(listener, 'connect'):