首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何优雅地中止pipelines管道?

如何优雅地中止pipelines管道?
EN

Stack Overflow用户
提问于 2015-04-30 22:44:16
回答 1查看 417关注 0票数 1

问题

我有一条管道链:

代码语言:javascript
复制
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中,在启动PipelineAMapreducePipelinePipelineB之前,我正在测试一些条件。如果条件失败,我希望中止EntryPipeline和所有后续管道。

问题

  1. 什么是优雅的管道流产?self.abort()是正确的方法还是我需要sys.exit()
  2. 如果我想在PipelineA内部做堕胎呢?例如,PipelineA成功启动,但防止后续管道(MapreducePipelinePipelineB)启动。

编辑:

最后,我将条件语句移出EntryPipeline,因此,只有在条件为真的情况下才开始整个工作。否则我认为尼克的回答是正确的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-01 18:33:29

由于文档当前的名称是"TODO: Talk有关显式中止和重试

我们将不得不阅读消息来源:

https://github.com/GoogleCloudPlatform/appengine-pipelines/blob/master/python/src/pipeline/pipeline.py#L703

代码语言:javascript
复制
  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,您可以调用但是如果你想要中止你自己,你需要引发中止().它会泡到顶端,杀死整棵树

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29979036

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档