Commit 8d3bc8d6 authored by Denis Bilenko's avatar Denis Bilenko

make Queue.empty() and Queue.full() compatible with the standard Queue

- it tried to take into account the greenlets currently blocking on get()/put()
  which was not useful and hard to reason about and incompatible with the standard Queue.
parent a36cc99c
......@@ -64,18 +64,15 @@ class Queue(object):
return len(self.queue)
def empty(self):
"""Return True if the queue is empty, False otherwise.
Queue is not empty if there are greenlets blocking on put()
"""
return not self.qsize() and not self.putters
"""Return ``True`` if the queue is empty, ``False`` otherwise."""
return not self.qsize()
def full(self):
"""Return True if the queue is full, False otherwise.
Queue(None) is never full.
"""
return self.qsize() + len(self.putters) - len(self.getters) >= self.maxsize
return self.qsize() >= self.maxsize
def put(self, item, block=True, timeout=None):
"""Put an item into the queue.
......
......@@ -265,7 +265,7 @@ class TestNoWait(TestCase):
assert q.empty(), q
assert q.full(), q
gevent.sleep(0)
assert not q.empty(), q
assert q.empty(), q
assert q.full(), q
core.active_event(store_result, util.wrap_errors(Exception, q.get_nowait))
gevent.sleep(0)
......@@ -287,7 +287,7 @@ class TestNoWait(TestCase):
assert q.full(), q
gevent.sleep(0)
assert q.empty(), q
assert not q.full(), q
assert q.full(), q
core.active_event(store_result, util.wrap_errors(Exception, q.put_nowait), 10)
assert not p.ready(), p
gevent.sleep(0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment