[New-bugs-announce] [issue7337] Add lossy queue to queue library module

Ben Bass report at bugs.python.org
Tue Nov 17 11:40:40 CET 2009


New submission from Ben Bass <benpaulbass at googlemail.com>:

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.

----------
components: Library (Lib)
messages: 95374
nosy: bpb
severity: normal
status: open
title: Add lossy queue to queue library module
type: feature request
versions: Python 2.7, Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7337>
_______________________________________


More information about the New-bugs-announce mailing list