Skip to content

Commit

Permalink
Cleanup InjectProcess and Backprojector
Browse files Browse the repository at this point in the history
Follow coroutine interface and use the started
flag already in the parent class.
  • Loading branch information
tfarago committed Feb 28, 2014
1 parent e4b62b3 commit bf21fc7
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions concert/ext/ufo.py
Expand Up @@ -43,6 +43,7 @@ class InjectProcess(object):
def __init__(self, graph, get_output=False):
self.input_task = Ufo.InputTask()
self.output_task = None
self._started = False

if isinstance(graph, Ufo.TaskGraph):
self.graph = graph
Expand Down Expand Up @@ -70,6 +71,17 @@ def __exit__(self, exc_type, exc_val, exc_tb):
self.wait()
return True

@coroutine
def __call__(self, consumer):
"""Co-routine compatible consumer."""
if not self._started:
self.start()

while True:
item = yield
self.insert(item)
consumer.send(self.result())

def start(self):
"""
Run the processing in a new thread.
Expand All @@ -82,6 +94,8 @@ def run_scheduler():

self.thread = threading.Thread(target=run_scheduler)
self.thread.start()
if not self._started:
self._started = True

def insert(self, array):
"""
Expand All @@ -104,12 +118,6 @@ def result(self):
self.output_task.release_output_buffer(buf)
return result

def consume(self):
"""Co-routine compatible consumer."""
while True:
item = yield
self.insert(item)

def wait(self):
"""Wait until processing has finished."""
self.input_task.stop()
Expand All @@ -133,7 +141,6 @@ def __init__(self, axis_pos=None):
self.ifft = self.pm.get_task('ifft', dimensions=1)
self.fltr = self.pm.get_task('filter')
self.backprojector = self.pm.get_task('backproject')
self._started = False

if axis_pos:
self.backprojector.props.axis_pos = axis_pos
Expand All @@ -156,11 +163,9 @@ def axis_position(self, position):
@coroutine
def __call__(self, consumer):
"""Get a sinogram, do filtered backprojection and send it to *consumer*."""
slice = None
if not self._started:
self.start()
self._started = True

slice = None

while True:
sinogram = yield
Expand Down

0 comments on commit bf21fc7

Please sign in to comment.