Simplification of node execution context, handle_result is now in step() as it is the only logical place where this will actually be called.

This commit is contained in:
Romain Dorgueil
2017-11-12 11:16:52 +01:00
parent 0b3694142b
commit 739a64d8f4
3 changed files with 19 additions and 23 deletions

View File

@ -1,5 +1,6 @@
import logging
import sys
import warnings
from queue import Empty
from time import sleep
from types import GeneratorType
@ -27,7 +28,7 @@ class NodeExecutionContext(WithStatistics, LoopingExecutionContext):
def __init__(self, wrapped, parent=None, services=None, _input=None, _outputs=None):
LoopingExecutionContext.__init__(self, wrapped, parent=parent, services=services)
WithStatistics.__init__(self, 'in', 'out', 'err')
WithStatistics.__init__(self, 'in', 'out', 'err', 'warn')
self.input = _input or Input()
self.outputs = _outputs or []
@ -125,19 +126,8 @@ class NodeExecutionContext(WithStatistics, LoopingExecutionContext):
input_bag = self.get()
# todo add timer
self.handle_results(input_bag, input_bag.apply(self._stack))
results = input_bag.apply(self._stack)
def kill(self):
if not self.started:
raise RuntimeError('Cannot kill a node context that has not started yet.')
if self.stopped:
raise RuntimeError('Cannot kill a node context that has already stopped.')
self._killed = True
def handle_results(self, input_bag, results):
# self._exec_time += timer.duration
# Put data onto output channels
@ -159,6 +149,15 @@ class NodeExecutionContext(WithStatistics, LoopingExecutionContext):
# self._exec_count += 1
pass
def kill(self):
if not self.started:
raise RuntimeError('Cannot kill a node context that has not started yet.')
if self.stopped:
raise RuntimeError('Cannot kill a node context that has already stopped.')
self._killed = True
def as_dict(self):
return {
'status': self.status,

View File

@ -61,12 +61,9 @@ class CsvReader(FileReader, CsvHandler):
for _ in range(0, self.skip):
next(reader)
for row in reader:
for lineno, row in enumerate(reader):
if len(row) != field_count:
warnings.warn('Got a line with %d fields, expecting %d.' % (
len(row),
field_count,
))
warnings.warn('Got %d fields on line #%d, expecting %d.' % (len(row), lineno, field_count,))
yield dict(zip(_headers, row))

View File

@ -28,8 +28,8 @@ class WithStatistics:
stats = tuple('{0}={1}'.format(name, cnt) for name, cnt in self.get_statistics(*args, **kwargs) if cnt > 0)
return (kwargs.get('prefix', '') + ' '.join(stats)) if len(stats) else ''
def increment(self, name):
self.statistics[name] += 1
def increment(self, name, *, amount=1):
self.statistics[name] += amount
class Timer: