fix twistedutil.protocol.ValueQueue in regard to new Queue class
This commit is contained in:
@@ -29,10 +29,10 @@ from twisted.python import failure
|
|||||||
|
|
||||||
from eventlet import proc
|
from eventlet import proc
|
||||||
from eventlet.api import getcurrent
|
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.
|
"""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
|
Useful if you send an exception over queue only once, and once sent it must be always
|
||||||
available.
|
available.
|
||||||
@@ -40,23 +40,18 @@ class ValueQueue(queue):
|
|||||||
|
|
||||||
def send(self, value=None, exc=None):
|
def send(self, value=None, exc=None):
|
||||||
if exc is not None or not self.has_error():
|
if exc is not None or not self.has_error():
|
||||||
queue.send(self, value, exc)
|
Queue.send(self, value, exc)
|
||||||
|
|
||||||
def wait(self):
|
def wait(self):
|
||||||
"""The difference from queue.wait: if there is an only item in the
|
"""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
|
Queue and it is an exception, raise it, but keep it in the Queue, so
|
||||||
that future calls to wait() will raise it again.
|
that future calls to wait() will raise it again.
|
||||||
"""
|
"""
|
||||||
self.sem.acquire()
|
|
||||||
if self.has_error() and len(self.items)==1:
|
if self.has_error() and len(self.items)==1:
|
||||||
# the last item, which is an exception, raise without emptying the queue
|
# the last item, which is an exception, raise without emptying the Queue
|
||||||
self.sem.release()
|
|
||||||
getcurrent().throw(*self.items[0][1])
|
getcurrent().throw(*self.items[0][1])
|
||||||
else:
|
else:
|
||||||
result, exc = self.items.popleft()
|
return Queue.wait(self)
|
||||||
if exc is not None:
|
|
||||||
getcurrent().throw(*exc)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def has_error(self):
|
def has_error(self):
|
||||||
return self.items and self.items[-1][1] is not None
|
return self.items and self.items[-1][1] is not None
|
||||||
|
Reference in New Issue
Block a user