|
|
|
@ -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): |
|
|
|
|