add a way to set the event to trigger, and fix a typo
This commit is contained in:
parent
1df0e7e629
commit
b7a615d02a
|
@ -48,6 +48,21 @@ class BufferedPipe (object):
|
||||||
self._buffer = array.array('B')
|
self._buffer = array.array('B')
|
||||||
self._closed = False
|
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):
|
def feed(self, data):
|
||||||
"""
|
"""
|
||||||
Feed new data into this pipe. This method is assumed to be called
|
Feed new data into this pipe. This method is assumed to be called
|
||||||
|
@ -133,7 +148,7 @@ class BufferedPipe (object):
|
||||||
self._event.clear()
|
self._event.clear()
|
||||||
else:
|
else:
|
||||||
out = self._buffer[:nbytes].tostring()
|
out = self._buffer[:nbytes].tostring()
|
||||||
del self.in_buffer[:nbytes]
|
del self._buffer[:nbytes]
|
||||||
finally:
|
finally:
|
||||||
self._lock.release()
|
self._lock.release()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue