From 51f9cee438f7498269c63a69121e9cf8b16b7d62 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 22 Jun 2009 15:56:34 +0700 Subject: [PATCH] fix twistedutil.protocol.ValueQueue in regard to new Queue class --- eventlet/twistedutil/protocol.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/eventlet/twistedutil/protocol.py b/eventlet/twistedutil/protocol.py index b778042..08620a0 100644 --- a/eventlet/twistedutil/protocol.py +++ b/eventlet/twistedutil/protocol.py @@ -29,10 +29,10 @@ from twisted.python import failure from eventlet import proc from eventlet.api import getcurrent -from eventlet.coros import queue, event +from eventlet.coros import Queue, event -class ValueQueue(queue): +class ValueQueue(Queue): """Queue that keeps the last item forever in the queue if it's an exception. Useful if you send an exception over queue only once, and once sent it must be always available. @@ -40,23 +40,18 @@ class ValueQueue(queue): def send(self, value=None, exc=None): if exc is not None or not self.has_error(): - queue.send(self, value, exc) + Queue.send(self, value, exc) def wait(self): - """The difference from queue.wait: if there is an only item in the - queue and it is an exception, raise it, but keep it in the queue, so + """The difference from Queue.wait: if there is an only item in the + Queue and it is an exception, raise it, but keep it in the Queue, so that future calls to wait() will raise it again. """ - self.sem.acquire() if self.has_error() and len(self.items)==1: - # the last item, which is an exception, raise without emptying the queue - self.sem.release() + # the last item, which is an exception, raise without emptying the Queue getcurrent().throw(*self.items[0][1]) else: - result, exc = self.items.popleft() - if exc is not None: - getcurrent().throw(*exc) - return result + return Queue.wait(self) def has_error(self): return self.items and self.items[-1][1] is not None