summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util/queue.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-12-06 15:53:59 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2013-12-06 16:34:20 -0500
commit300264ab38def29a4a24a83b39aece0d0332e83d (patch)
treecb5229af2324623c358574e1fc46a320183cf01d /lib/sqlalchemy/util/queue.py
parentb653fb3a23a0388814d9ab79b884d64d396baff1 (diff)
downloadsqlalchemy-300264ab38def29a4a24a83b39aece0d0332e83d.tar.gz
- Made a slight adjustment to the logic which waits for a pooled
connection to be available, such that for a connection pool with no timeout specified, it will every half a second break out of the wait to check for the so-called "abort" flag, which allows the waiter to break out in case the whole connection pool was dumped; normally the waiter should break out due to a notify_all() but it's possible this notify_all() is missed in very slim cases. This is an extension of logic first introduced in 0.8.0, and the issue has only been observed occasionally in stress tests.
Diffstat (limited to 'lib/sqlalchemy/util/queue.py')
-rw-r--r--lib/sqlalchemy/util/queue.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/sqlalchemy/util/queue.py b/lib/sqlalchemy/util/queue.py
index b66738aff..639b23a93 100644
--- a/lib/sqlalchemy/util/queue.py
+++ b/lib/sqlalchemy/util/queue.py
@@ -151,7 +151,6 @@ class Queue:
return an item if one is immediately available, else raise the
``Empty`` exception (`timeout` is ignored in that case).
"""
-
self.not_empty.acquire()
try:
if not block:
@@ -159,7 +158,11 @@ class Queue:
raise Empty
elif timeout is None:
while self._empty():
- self.not_empty.wait()
+ # wait for only half a second, then
+ # loop around, so that we can see a change in
+ # _sqla_abort_context in case we missed the notify_all()
+ # called by abort()
+ self.not_empty.wait(.5)
if self._sqla_abort_context:
raise SAAbort(self._sqla_abort_context)
else:
@@ -188,6 +191,9 @@ class Queue:
if not self.not_full.acquire(False):
return
try:
+ # note that this is now optional
+ # as the waiters in get() both loop around
+ # to check the _sqla_abort_context flag periodically
self.not_empty.notify_all()
finally:
self.not_full.release()