diff options
author | Guido van Rossum <guido@python.org> | 2014-01-26 01:24:51 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2014-01-26 01:24:51 (GMT) |
commit | fef7098ef9282cfc8a2c480408de351d5bf36fb1 (patch) | |
tree | 4653a6a6d0c73b2cede5d9dbd418b75c03b68224 /Lib | |
parent | ab3c88983bc6c2a6ae98625296eef9d7588c8d69 (diff) | |
download | cpython-fef7098ef9282cfc8a2c480408de351d5bf36fb1.zip cpython-fef7098ef9282cfc8a2c480408de351d5bf36fb1.tar.gz cpython-fef7098ef9282cfc8a2c480408de351d5bf36fb1.tar.bz2 |
asyncio: Rename {Empty,Full} to {QueueEmpty,QueueFull} and no longer get them from queue.py.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/asyncio/queues.py | 28 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_queues.py | 4 |
2 files changed, 21 insertions, 11 deletions
diff --git a/Lib/asyncio/queues.py b/Lib/asyncio/queues.py index e900278..bd62c60 100644 --- a/Lib/asyncio/queues.py +++ b/Lib/asyncio/queues.py @@ -1,11 +1,10 @@ """Queues""" __all__ = ['Queue', 'PriorityQueue', 'LifoQueue', 'JoinableQueue', - 'Full', 'Empty'] + 'QueueFull', 'QueueEmpty'] import collections import heapq -import queue from . import events from . import futures @@ -13,9 +12,20 @@ from . import locks from .tasks import coroutine -# Re-export queue.Full and .Empty exceptions. -Full = queue.Full -Empty = queue.Empty +class QueueEmpty(Exception): + 'Exception raised by Queue.get(block=0)/get_nowait().' + pass + + +class QueueFull(Exception): + 'Exception raised by Queue.put(block=0)/put_nowait().' + pass + + +# Un-exported aliases for temporary backward compatibility. +# Will disappear soon. +Full = QueueFull +Empty = QueueEmpty class Queue: @@ -134,7 +144,7 @@ class Queue: def put_nowait(self, item): """Put an item into the queue without blocking. - If no free slot is immediately available, raise Full. + If no free slot is immediately available, raise QueueFull. """ self._consume_done_getters() if self._getters: @@ -149,7 +159,7 @@ class Queue: getter.set_result(self._get()) elif self._maxsize > 0 and self._maxsize == self.qsize(): - raise Full + raise QueueFull else: self._put(item) @@ -184,7 +194,7 @@ class Queue: def get_nowait(self): """Remove and return an item from the queue. - Return an item if one is immediately available, else raise Empty. + Return an item if one is immediately available, else raise QueueEmpty. """ self._consume_done_putters() if self._putters: @@ -199,7 +209,7 @@ class Queue: elif self.qsize(): return self._get() else: - raise Empty + raise QueueEmpty class PriorityQueue(Queue): diff --git a/Lib/test/test_asyncio/test_queues.py b/Lib/test/test_asyncio/test_queues.py index a06ed50..fc2bf46 100644 --- a/Lib/test/test_asyncio/test_queues.py +++ b/Lib/test/test_asyncio/test_queues.py @@ -230,7 +230,7 @@ class QueueGetTests(_QueueTestBase): def test_nonblocking_get_exception(self): q = asyncio.Queue(loop=self.loop) - self.assertRaises(asyncio.Empty, q.get_nowait) + self.assertRaises(asyncio.QueueEmpty, q.get_nowait) def test_get_cancelled(self): @@ -337,7 +337,7 @@ class QueuePutTests(_QueueTestBase): def test_nonblocking_put_exception(self): q = asyncio.Queue(maxsize=1, loop=self.loop) q.put_nowait(1) - self.assertRaises(asyncio.Full, q.put_nowait, 2) + self.assertRaises(asyncio.QueueFull, q.put_nowait, 2) def test_put_cancelled(self): q = asyncio.Queue(loop=self.loop) |