From d261318e1a80b53abd677eb30f7bc5f91bae9dd6 Mon Sep 17 00:00:00 2001 From: Oleg Antonyan Date: Thu, 27 Nov 2014 07:11:06 +0200 Subject: [PATCH] In queues added option to remove first element on addind new if queue is full --- sleekxmpp/util/__init__.py | 9 +++++++-- sleekxmpp/xmlstream/xmlstream.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sleekxmpp/util/__init__.py b/sleekxmpp/util/__init__.py index 05286d33..47a935af 100644 --- a/sleekxmpp/util/__init__.py +++ b/sleekxmpp/util/__init__.py @@ -32,12 +32,17 @@ def _gevent_threads_enabled(): if _gevent_threads_enabled(): import gevent.queue as queue - Queue = queue.JoinableQueue + _queue = queue.JoinableQueue else: try: import queue except ImportError: import Queue as queue - Queue = queue.Queue + _queue = queue.Queue +class Queue(_queue): + def put(self, item, block=True, timeout=None): + if _queue.full(self): + _queue.get(self) + return _queue.put(self, item, block, timeout) QueueEmpty = queue.Empty diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index e011cf3d..dc9928f8 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -291,7 +291,7 @@ class XMLStream(object): self.event_queue = Queue() #: A queue of string data to be sent over the stream. - self.send_queue = Queue() + self.send_queue = Queue(maxsize=256) self.send_queue_lock = threading.Lock() self.send_lock = threading.RLock()