mirror of
https://github.com/python/cpython.git
synced 2024-12-05 07:43:50 +08:00
asyncio: Rename {Empty,Full} to {QueueEmpty,QueueFull} and no longer get them from queue.py.
This commit is contained in:
parent
ab3c88983b
commit
fef7098ef9
@ -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):
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user