def run(self, status): assert self._finalized, "PM must be finalized before run()" for pipeline_name in self.pipeline_order: event(pipeline_name) is_final_pipeline = pipeline_name == self.pipeline_order[-1] for stage, stage_name in self.pipeline_stages[pipeline_name]: try: event(stage_name) stage() except _EarlyPipelineCompletion as e: return e.result except BaseException as e: msg = "Failed at %s (%s)" % (pipeline_name, stage_name) patched_exception = self._patch_error(msg, e) # No more fallback pipelines? if is_final_pipeline: raise patched_exception # Go to next fallback pipeline else: status.fail_reason = patched_exception break else: return None # TODO save all error information raise CompilerError("All pipelines have failed")
def _compile_core(self): """ Populate and run compiler pipeline """ pms = self.define_pipelines() for pm in pms: pipeline_name = pm.pipeline_name func_name = "%s.%s" % (self.state.func_id.modname, self.state.func_id.func_qualname) event("Pipeline: %s for %s" % (pipeline_name, func_name)) self.state.metadata['pipeline_times'] = { pipeline_name: pm.exec_times } is_final_pipeline = pm == pms[-1] res = None try: pm.run(self.state) if self.state.cr is not None: break except _EarlyPipelineCompletion as e: res = e.result break except Exception as e: self.state.status.fail_reason = e if is_final_pipeline: raise e else: raise CompilerError("All available pipelines exhausted") # Pipeline is done, remove self reference to release refs to user code self.state.pipeline = None # organise a return if res is not None: # Early pipeline completion return res else: assert self.state.cr is not None return self.state.cr