]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
when QueuePool times out it raises a TimeoutError instead of
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 26 Jun 2006 02:06:44 +0000 (02:06 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 26 Jun 2006 02:06:44 +0000 (02:06 +0000)
erroneously making another connection

CHANGES
lib/sqlalchemy/exceptions.py
lib/sqlalchemy/pool.py
test/engine/pool.py

diff --git a/CHANGES b/CHANGES
index 431546c478111d0aed683c9f3b2e4f3043c4b03a..154829df8fc455d32a4acc4b92603494447e335a 100644 (file)
--- 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
index 2713fb7543b50f4babd262ada66b51e6ce5d4084..6aeca3efc4e2244c17dd16d0e0b52fc2c991e783 100644 (file)
@@ -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()"""
index a8715ee1b51c12ab9c9157399604de23d36534f8..b086aae9f6e4aae669c8fd549cb341c255f0711a 100644 (file)
@@ -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()
 
index 9a8c7cffdc6cc91f2bb52261b23771f27c183bc5..fd09eb1c7335399d9e3c8cf791277b1eb4f6c576 100644 (file)
@@ -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)