add a way to set the event to trigger, and fix a typo
This commit is contained in:
Robey Pointer 2006-04-11 15:47:33 -07:00
parent 1df0e7e629
commit b7a615d02a
1 changed files with 16 additions and 1 deletions

View File

@ -48,6 +48,21 @@ class BufferedPipe (object):
self._buffer = array.array('B')
self._closed = False
def set_event(self, event):
"""
Set an event on this buffer. When data is ready to be read (or the
buffer has been closed), the event will be set. When no data is
ready, the event will be cleared.
@param event: the event to set/clear
@type event: Event
"""
self._event = event
if len(self._buffer) > 0:
event.set()
else:
event.clear()
def feed(self, data):
"""
Feed new data into this pipe. This method is assumed to be called
@ -133,7 +148,7 @@ class BufferedPipe (object):
self._event.clear()
else:
out = self._buffer[:nbytes].tostring()
del self.in_buffer[:nbytes]
del self._buffer[:nbytes]
finally:
self._lock.release()