[examples] Fix examples, fix termination bug with unrecoverable errors.
This commit is contained in:
@ -96,8 +96,8 @@ graph = bonobo.Graph(
|
|||||||
),
|
),
|
||||||
normalize,
|
normalize,
|
||||||
filter_france,
|
filter_france,
|
||||||
|
bonobo.JsonWriter(path='fablabs.txt', ioformat='arg0'),
|
||||||
bonobo.Tee(display),
|
bonobo.Tee(display),
|
||||||
bonobo.JsonWriter(path='fablabs.txt'),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@ -9,13 +9,16 @@ class OddOnlyFilter(Filter):
|
|||||||
|
|
||||||
|
|
||||||
@Filter
|
@Filter
|
||||||
def MultiplesOfThreeOnlyFilter(self, i):
|
def multiples_of_three(i):
|
||||||
return not (i % 3)
|
return not (i % 3)
|
||||||
|
|
||||||
|
|
||||||
graph = bonobo.Graph(
|
graph = bonobo.Graph(
|
||||||
lambda: tuple(range(50)),
|
lambda: tuple(range(50)),
|
||||||
OddOnlyFilter(),
|
OddOnlyFilter(),
|
||||||
MultiplesOfThreeOnlyFilter(),
|
multiples_of_three,
|
||||||
print,
|
print,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
bonobo.run(graph)
|
||||||
|
|||||||
@ -14,3 +14,6 @@ graph = bonobo.Graph(
|
|||||||
pause,
|
pause,
|
||||||
print,
|
print,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
bonobo.run(graph)
|
||||||
|
|||||||
@ -8,7 +8,7 @@ def split_one(line):
|
|||||||
graph = bonobo.Graph(
|
graph = bonobo.Graph(
|
||||||
bonobo.FileReader('coffeeshops.txt'),
|
bonobo.FileReader('coffeeshops.txt'),
|
||||||
split_one,
|
split_one,
|
||||||
bonobo.JsonWriter('coffeeshops.json'),
|
bonobo.JsonWriter('coffeeshops.json', ioformat='arg0'),
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@ -95,6 +95,7 @@ class NodeExecutionContext(WithStatistics, LoopingExecutionContext):
|
|||||||
continue
|
continue
|
||||||
except UnrecoverableError as exc:
|
except UnrecoverableError as exc:
|
||||||
self.handle_error(exc, traceback.format_exc())
|
self.handle_error(exc, traceback.format_exc())
|
||||||
|
self.input.shutdown()
|
||||||
break
|
break
|
||||||
except Exception as exc: # pylint: disable=broad-except
|
except Exception as exc: # pylint: disable=broad-except
|
||||||
self.handle_error(exc, traceback.format_exc())
|
self.handle_error(exc, traceback.format_exc())
|
||||||
|
|||||||
@ -77,6 +77,12 @@ class Input(Queue, Readable, Writable):
|
|||||||
|
|
||||||
return Queue.put(self, data, block, timeout)
|
return Queue.put(self, data, block, timeout)
|
||||||
|
|
||||||
|
def _decrement_runlevel(self):
|
||||||
|
if self._runlevel == 1:
|
||||||
|
self.on_finalize()
|
||||||
|
self._runlevel -= 1
|
||||||
|
self.on_end()
|
||||||
|
|
||||||
def get(self, block=True, timeout=None):
|
def get(self, block=True, timeout=None):
|
||||||
if not self.alive:
|
if not self.alive:
|
||||||
raise InactiveReadableError('Cannot get() on an inactive {}.'.format(Readable.__name__))
|
raise InactiveReadableError('Cannot get() on an inactive {}.'.format(Readable.__name__))
|
||||||
@ -84,13 +90,7 @@ class Input(Queue, Readable, Writable):
|
|||||||
data = Queue.get(self, block, timeout)
|
data = Queue.get(self, block, timeout)
|
||||||
|
|
||||||
if data == END:
|
if data == END:
|
||||||
if self._runlevel == 1:
|
self._decrement_runlevel()
|
||||||
self.on_finalize()
|
|
||||||
|
|
||||||
self._runlevel -= 1
|
|
||||||
|
|
||||||
# callback
|
|
||||||
self.on_end()
|
|
||||||
|
|
||||||
if not self.alive:
|
if not self.alive:
|
||||||
raise InactiveReadableError(
|
raise InactiveReadableError(
|
||||||
@ -100,6 +100,10 @@ class Input(Queue, Readable, Writable):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def shutdown(self):
|
||||||
|
while self._runlevel >= 1:
|
||||||
|
self._decrement_runlevel()
|
||||||
|
|
||||||
def empty(self):
|
def empty(self):
|
||||||
self.mutex.acquire()
|
self.mutex.acquire()
|
||||||
while self._qsize() and self.queue[0] == END:
|
while self._qsize() and self.queue[0] == END:
|
||||||
|
|||||||
Reference in New Issue
Block a user