diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-03-30 12:30:54 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-03-30 12:30:54 -0400 |
| commit | 218c3cb365e7354a312bc3e24e1cb21a2487459c (patch) | |
| tree | 0a96a04800026db85839eb04fae51907aa1c2783 /lib/sqlalchemy/pool.py | |
| parent | 90aa366fb3731892fd75455c81cdcc9e11268130 (diff) | |
| download | sqlalchemy-218c3cb365e7354a312bc3e24e1cb21a2487459c.tar.gz | |
- AssertionPool now stores the traceback indicating
where the currently checked out connection was
acquired; this traceback is reported within
the assertion raised upon a second concurrent
checkout; courtesy Gunnlaugur Briem
[ticket:2103]
Diffstat (limited to 'lib/sqlalchemy/pool.py')
| -rw-r--r-- | lib/sqlalchemy/pool.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index a5b06f63a..6d7542fb5 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -16,11 +16,12 @@ regular DB-API connect() methods to be transparently managed by a SQLAlchemy connection pool. """ -import weakref, time, threading +import weakref, time, traceback from sqlalchemy import exc, log, event, events, interfaces, util from sqlalchemy.util import queue as sqla_queue -from sqlalchemy.util import threading, pickle, memoized_property +from sqlalchemy.util import threading, pickle, memoized_property, \ + chop_traceback proxies = {} @@ -815,17 +816,23 @@ class StaticPool(Pool): return self.connection class AssertionPool(Pool): - """A Pool that allows at most one checked out connection at any given + """A :class:`.Pool` that allows at most one checked out connection at any given time. This will raise an exception if more than one connection is checked out at a time. Useful for debugging code that is using more connections than desired. + + :class:`.AssertionPool` also logs a traceback of where + the original connection was checked out, and reports + this in the assertion error raised (new in 0.7). """ def __init__(self, *args, **kw): self._conn = None self._checked_out = False + self._store_traceback = kw.pop('store_traceback', True) + self._checkout_traceback = None Pool.__init__(self, *args, **kw) def status(self): @@ -850,12 +857,19 @@ class AssertionPool(Pool): def _do_get(self): if self._checked_out: - raise AssertionError("connection is already checked out") + if self._checkout_traceback: + suffix = ' at:\n%s' % ''.join( + chop_traceback(self._checkout_traceback)) + else: + suffix = '' + raise AssertionError("connection is already checked out" + suffix) if not self._conn: self._conn = self._create_connection() self._checked_out = True + if self._store_traceback: + self._checkout_traceback = traceback.format_stack() return self._conn class _DBProxy(object): |
