Mike Bayer committed 4183fbc

attempting to fix reentrant condition that can happen with Queue.Queue

  • Participants
  • Parent commits 017f090

Comments (0)

Files changed (2)

 - fixed bug when specifying explicit module to mysql dialect
 - when QueuePool times out it raises a TimeoutError instead of
 erroneously making another connection
+- attempting to fix a rare hang that can occur with Queue.Queue
 - overhaul to mapper compilation to be deferred.  this allows mappers

File lib/sqlalchemy/

     import thread
+    import threading
     import dummythread as thread
+    import dummythreading as threading
 proxies = {}
         Pool.__init__(self, **params)
         self._creator = creator
         self._pool = Queue.Queue(pool_size)
+        # modify the pool's mutex to be an RLock.  this is because a rare condition can
+        # occur where a ConnectionFairy's __del__ method gets called within the get() method
+        # of the Queue (and then tries to do a put() within the get()), causing a re-entrant hang.
+        # the RLock allows the mutex to be reentrant within that case.
+        self._pool.mutex = threading.RLock()
+        self._pool.not_empty = threading.Condition(self._pool.mutex)
+        self._pool.not_full = threading.Condition(self._pool.mutex)
         self._overflow = 0 - pool_size
         self._max_overflow = max_overflow
         self._timeout = timeout