[Python-checkins] cpython (3.4): Issue #21723: asyncio.Queue: support any type of number (ex: float) for the

victor.stinner python-checkins at python.org
Tue Jun 17 23:41:00 CEST 2014


http://hg.python.org/cpython/rev/ccfc13183fea
changeset: 91253:ccfc13183fea
branch: 3.4
parent: 91250:385d4fea9f13
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Jun 17 23:36:21 2014 +0200
summary:
 Issue #21723: asyncio.Queue: support any type of number (ex: float) for the
maximum size. Patch written by Vajrasky Kok.
files:
 Lib/asyncio/queues.py | 6 +++---
 Lib/test/test_asyncio/test_queues.py | 15 +++++++++++++++
 Misc/NEWS | 3 +++
 3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/Lib/asyncio/queues.py b/Lib/asyncio/queues.py
--- a/Lib/asyncio/queues.py
+++ b/Lib/asyncio/queues.py
@@ -105,7 +105,7 @@
 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 @@
 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 @@
 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
--- a/Lib/test/test_asyncio/test_queues.py
+++ b/Lib/test/test_asyncio/test_queues.py
@@ -339,6 +339,21 @@
 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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,9 @@
 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.
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /