From 08a6a8b51916ab1d084a0070bbb07001cabb1c38 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 22 Sep 2013 20:35:40 -0400 Subject: - Removed some now unneeded version checks [ticket:2829] courtesy alex gaynor --- lib/sqlalchemy/util/queue.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'lib/sqlalchemy/util/queue.py') diff --git a/lib/sqlalchemy/util/queue.py b/lib/sqlalchemy/util/queue.py index 537526bef..b66738aff 100644 --- a/lib/sqlalchemy/util/queue.py +++ b/lib/sqlalchemy/util/queue.py @@ -25,14 +25,7 @@ within QueuePool. from collections import deque from time import time as _time from .compat import threading -import sys -if sys.version_info < (2, 6): - def notify_all(condition): - condition.notify() -else: - def notify_all(condition): - condition.notify_all() __all__ = ['Empty', 'Full', 'Queue', 'SAAbort'] @@ -195,7 +188,7 @@ class Queue: if not self.not_full.acquire(False): return try: - notify_all(self.not_empty) + self.not_empty.notify_all() finally: self.not_full.release() -- cgit v1.2.1 From 300264ab38def29a4a24a83b39aece0d0332e83d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 6 Dec 2013 15:53:59 -0500 Subject: - 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. --- lib/sqlalchemy/util/queue.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/util/queue.py') 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() -- cgit v1.2.1 From f89d4d216bd7605c920b7b8a10ecde6bfea2238c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 5 Jan 2014 16:57:05 -0500 Subject: - happy new year --- lib/sqlalchemy/util/queue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/sqlalchemy/util/queue.py') diff --git a/lib/sqlalchemy/util/queue.py b/lib/sqlalchemy/util/queue.py index 639b23a93..82ff55a5d 100644 --- a/lib/sqlalchemy/util/queue.py +++ b/lib/sqlalchemy/util/queue.py @@ -1,5 +1,5 @@ # util/queue.py -# Copyright (C) 2005-2013 the SQLAlchemy authors and contributors +# Copyright (C) 2005-2014 the SQLAlchemy authors and contributors # # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -- cgit v1.2.1