diff options
Diffstat (limited to 'python/qpid/queue.py')
-rw-r--r-- | python/qpid/queue.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/python/qpid/queue.py b/python/qpid/queue.py index ea8f00d091..a8a5c0d9ad 100644 --- a/python/qpid/queue.py +++ b/python/qpid/queue.py @@ -25,8 +25,7 @@ content of a queue can be notified if the queue is no longer in use. from Queue import Queue as BaseQueue, Empty, Full from threading import Thread - -class Closed(Exception): pass +from exceptions import Closed class Queue(BaseQueue): @@ -37,6 +36,7 @@ class Queue(BaseQueue): BaseQueue.__init__(self, *args, **kwargs) self.error = None self.listener = None + self.exc_listener = None self.thread = None def close(self, error = None): @@ -53,15 +53,20 @@ class Queue(BaseQueue): else: return result - def listen(self, listener): + def listen(self, listener, exc_listener = None): + if listener is None and exc_listener is not None: + raise ValueError("cannot set exception listener without setting listener") + self.listener = listener - if listener == None: - if self.thread != None: + self.exc_listener = exc_listener + + if listener is None: + if self.thread is not None: self.put(Queue.STOP) self.thread.join() self.thread = None else: - if self.thread == None: + if self.thread is None: self.thread = Thread(target = self.run) self.thread.setDaemon(True) self.thread.start() @@ -72,5 +77,7 @@ class Queue(BaseQueue): o = self.get() if o == Queue.STOP: break self.listener(o) - except Closed: + except Closed, e: + if self.exc_listener is not None: + self.exc_listener(e) break |