This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bpb
Recipients bpb
Date 2009-11-17.10:40:38
SpamBayes Score 9.908857e-08
Marked as misclassified No
Message-id <1258454440.69.0.147012340761.issue7337@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2009-11-17 10:40:41bpbsetrecipients: + bpb
2009-11-17 10:40:40bpbsetmessageid: <1258454440.69.0.147012340761.issue7337@psf.upfronthosting.co.za>
2009-11-17 10:40:39bpblinkissue7337 messages
2009-11-17 10:40:38bpbcreate