问题
我有一条管道链:
class PipelineA(base_handler.PipelineBase):
def run(self, *args):
# do something
class PipelineB(base_handler.PipelineBase):
def run(self, *args):
# do something
class EntryPipeline(base_handler.PipelineBase):
def run(self):
if some_condition():
self.abort("Condition failed. Pipeline aborted!")
yield PipelineA()
mr_output = yield mapreduce_pipeline.MapreducePipeline(
# mapreduce configs here
# ...
)
yield PipelineB(mr_output)
p = EntryPipeline()
p.start()在EntryPipeline中,在启动PipelineA、MapreducePipeline和PipelineB之前,我正在测试一些条件。如果条件失败,我希望中止EntryPipeline和所有后续管道。
问题
self.abort()是正确的方法还是我需要sys.exit()PipelineA内部做堕胎呢?例如,PipelineA成功启动,但防止后续管道(MapreducePipeline和PipelineB)启动。编辑:
最后,我将条件语句移出EntryPipeline,因此,只有在条件为真的情况下才开始整个工作。否则我认为尼克的回答是正确的。
发布于 2015-05-01 18:33:29
由于文档当前的名称是"TODO: Talk有关显式中止和重试“
我们将不得不阅读消息来源:
def abort(self, abort_message=''):
"""Mark the entire pipeline up to the root as aborted.
Note this should only be called from *outside* the context of a running
pipeline. Synchronous and generator pipelines should raise the 'Abort'
exception to cause this behavior during execution.
Args:
abort_message: Optional message explaining why the abort happened.
Returns:
True if the abort signal was sent successfully; False if the pipeline
could not be aborted for any reason.
"""因此,如果您有一个some_pipeline的句柄不是self,您可以调用但是如果你想要中止你自己,你需要引发中止().它会泡到顶端,杀死整棵树
https://stackoverflow.com/questions/29979036
复制相似问题