From dc1cc365c244a0f0c40c6b2348b868f8f98b8020 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 26 Jun 2006 02:06:44 +0000 Subject: [PATCH] when QueuePool times out it raises a TimeoutError instead of erroneously making another connection --- CHANGES | 2 ++ lib/sqlalchemy/exceptions.py | 4 ++++ lib/sqlalchemy/pool.py | 4 +++- test/engine/pool.py | 9 ++++++--- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 431546c478..154829df8f 100644 --- a/CHANGES +++ b/CHANGES @@ -18,6 +18,8 @@ reserved word tablename.....* [ticket:206] - more fixes to inheritance, related to many-to-many relations properly saving - fixed bug when specifying explicit module to mysql dialect +- when QueuePool times out it raises a TimeoutError instead of +erroneously making another connection 0.2.3 - overhaul to mapper compilation to be deferred. this allows mappers diff --git a/lib/sqlalchemy/exceptions.py b/lib/sqlalchemy/exceptions.py index 2713fb7543..6aeca3efc4 100644 --- a/lib/sqlalchemy/exceptions.py +++ b/lib/sqlalchemy/exceptions.py @@ -24,6 +24,10 @@ class ArgumentError(SQLAlchemyError): """raised for all those conditions where invalid arguments are sent to constructed objects. This error generally corresponds to construction time state errors.""" pass + +class TimeoutError(SQLAlchemyError): + """raised when a connection pool times out on getting a connection""" + pass class FlushError(SQLAlchemyError): """raised when an invalid condition is detected upon a flush()""" diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index a8715ee1b5..b086aae9f6 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -11,7 +11,7 @@ be managed automatically, based on module type and connect arguments, simply by calling regular DBAPI connect() methods.""" import Queue, weakref, string, cPickle -import util +import util, exceptions try: import thread @@ -225,6 +225,8 @@ class QueuePool(Pool): try: return self._pool.get(self._max_overflow > -1 and self._overflow >= self._max_overflow, self._timeout) except Queue.Empty: + if self._overflow >= self._max_overflow: + raise exceptions.TimeoutError("QueuePool limit of size %d overflow %d reached, connection timed out" % (self.size(), self.overflow())) self._overflow += 1 return self._creator() diff --git a/test/engine/pool.py b/test/engine/pool.py index 9a8c7cffdc..fd09eb1c73 100644 --- a/test/engine/pool.py +++ b/test/engine/pool.py @@ -3,7 +3,7 @@ import unittest, sys, os, time from pysqlite2 import dbapi2 as sqlite import sqlalchemy.pool as pool - +import sqlalchemy.exceptions as exceptions class PoolTest(PersistTest): def setUp(self): @@ -96,8 +96,11 @@ class PoolTest(PersistTest): c2 = p.get() c3 = p.get() now = time.time() - c4 = p.get() - assert int(time.time() - now) == 2 + try: + c4 = p.get() + assert False + except exceptions.TimeoutError, e: + assert int(time.time() - now) == 2 def testthreadlocal_del(self): self._do_testthreadlocal(useclose=False) -- 2.47.3