Message95374
Many applications would benefit from 'connectionless' queues, i.e. they
don't want to care whether anything is reading from the other end.
Using current queue module classes this is not practical, because there
is a choice between unbounded memory consumption or blocking. I propose
adding a 'LossyQueue' class in the queue module which would allow
bounded memory consumption without blocking on put. (i.e. items are
dropped in fifo manner beyond a certain limit). In my view this is at
least as natural as the PriorityQueue and LifoQueue extensions in that
module.
Outline as follows:
class LossyQueue(Queue):
"Queue subclass which drops items on overflow"
def _init(self, maxsize):
if maxsize > 0:
# build the deque with maxsize limit
self.queue = deque(maxlen=maxsize)
else:
# same as normal Queue instance
self.queue = collections.deque()
# deque alone handles maxsize,
# so we pretend we have none
self.maxsize = 0
if there is interest in this I will offer a proper patch with docs and
tests. |
|
Date |
User |
Action |
Args |
2009-11-17 10:40:41 | bpb | set | recipients:
+ bpb |
2009-11-17 10:40:40 | bpb | set | messageid: <1258454440.69.0.147012340761.issue7337@psf.upfronthosting.co.za> |
2009-11-17 10:40:39 | bpb | link | issue7337 messages |
2009-11-17 10:40:38 | bpb | create | |
|