Mike Bayer committed 017f090

when QueuePool times out it raises a TimeoutError instead of
erroneously making another connection

  • Participants
  • Parent commits a819367

Comments (0)

Files changed (4)

 - 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
 - overhaul to mapper compilation to be deferred.  this allows mappers


     """raised for all those conditions where invalid arguments are sent to constructed
     objects.  This error generally corresponds to construction time state errors."""
+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()"""


  simply by calling regular DBAPI connect() methods."""
 import Queue, weakref, string, cPickle
-import util
+import util, exceptions
     import thread
             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()


 from pysqlite2 import dbapi2 as sqlite
 import sqlalchemy.pool as pool
+import sqlalchemy.exceptions as exceptions 
 class PoolTest(PersistTest):
     def setUp(self):
         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):