From 76a8cdcdaecb25cad58b015887e94a1393f6a425 Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Tue, 28 Jan 2014 21:00:41 +0000 Subject: [PATCH] queue: Make join not wait if there are no unfinished tasks This fixes GitHub issue #54 --- eventlet/queue.py | 3 ++- tests/queue_test.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/eventlet/queue.py b/eventlet/queue.py index 77077cf..a8cafce 100644 --- a/eventlet/queue.py +++ b/eventlet/queue.py @@ -418,7 +418,8 @@ class Queue(LightQueue): that the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero, :meth:`join` unblocks. ''' - self._cond.wait() + if self.unfinished_tasks > 0: + self._cond.wait() class PriorityQueue(Queue): diff --git a/tests/queue_test.py b/tests/queue_test.py index 2135b19..43c28f5 100644 --- a/tests/queue_test.py +++ b/tests/queue_test.py @@ -253,6 +253,10 @@ class TestQueue(LimitedTestCase): assert channel.unfinished_tasks == 0, channel.unfinished_tasks gt.wait() + def test_join_doesnt_block_when_queue_is_already_empty(self): + queue = eventlet.Queue() + queue.join() + def store_result(result, func, *args): try: