summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-17 21:36:21 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-06-17 21:36:21 (GMT)
commit66dc6b0f5355857ea73f59e6eb2066bf6604d322 (patch)
tree2b0623f93acf592dc56417b44d8afefba4ef9d48
parent14fbe72777b5250ad3ca9867916a7740eebad9bb (diff)
downloadcpython-66dc6b0f5355857ea73f59e6eb2066bf6604d322.zip
cpython-66dc6b0f5355857ea73f59e6eb2066bf6604d322.tar.gz
cpython-66dc6b0f5355857ea73f59e6eb2066bf6604d322.tar.bz2
Issue #21723: asyncio.Queue: support any type of number (ex: float) for the
maximum size. Patch written by Vajrasky Kok.
-rw-r--r--Lib/asyncio/queues.py6
-rw-r--r--Lib/test/test_asyncio/test_queues.py15
-rw-r--r--Misc/NEWS3
3 files changed, 21 insertions, 3 deletions
diff --git a/Lib/asyncio/queues.py b/Lib/asyncio/queues.py
index 6283db3..57afb05 100644
--- a/Lib/asyncio/queues.py
+++ b/Lib/asyncio/queues.py
@@ -105,7 +105,7 @@ class Queue:
if self._maxsize <= 0:
return False
else:
- return self.qsize() == self._maxsize
+ return self.qsize() >= self._maxsize
@coroutine
def put(self, item):
@@ -126,7 +126,7 @@ class Queue:
self._put(item)
getter.set_result(self._get())
- elif self._maxsize > 0 and self._maxsize == self.qsize():
+ elif self._maxsize > 0 and self._maxsize <= self.qsize():
waiter = futures.Future(loop=self._loop)
self._putters.append((item, waiter))
@@ -152,7 +152,7 @@ class Queue:
self._put(item)
getter.set_result(self._get())
- elif self._maxsize > 0 and self._maxsize == self.qsize():
+ elif self._maxsize > 0 and self._maxsize <= self.qsize():
raise QueueFull
else:
self._put(item)
diff --git a/Lib/test/test_asyncio/test_queues.py b/Lib/test/test_asyncio/test_queues.py
index f79fee2..820234d 100644
--- a/Lib/test/test_asyncio/test_queues.py
+++ b/Lib/test/test_asyncio/test_queues.py
@@ -339,6 +339,21 @@ class QueuePutTests(_QueueTestBase):
q.put_nowait(1)
self.assertRaises(asyncio.QueueFull, q.put_nowait, 2)
+ def test_float_maxsize(self):
+ q = asyncio.Queue(maxsize=1.3, loop=self.loop)
+ q.put_nowait(1)
+ q.put_nowait(2)
+ self.assertTrue(q.full())
+ self.assertRaises(asyncio.QueueFull, q.put_nowait, 3)
+
+ q = asyncio.Queue(maxsize=1.3, loop=self.loop)
+ @asyncio.coroutine
+ def queue_put():
+ yield from q.put(1)
+ yield from q.put(2)
+ self.assertTrue(q.full())
+ self.loop.run_until_complete(queue_put())
+
def test_put_cancelled(self):
q = asyncio.Queue(loop=self.loop)
diff --git a/Misc/NEWS b/Misc/NEWS
index ec8b4d9..6e333a4 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,9 @@ Core and Builtins
Library
-------
+- Issue #21723: asyncio.Queue: support any type of number (ex: float) for the
+ maximum size. Patch written by Vajrasky Kok.
+
- Issue #21326: Add a new is_closed() method to asyncio.BaseEventLoop.
run_forever() and run_until_complete() methods of asyncio.BaseEventLoop now
raise an exception if the event loop was closed.