def __init__(self, function, interpreter): LambdaFunction.__init__(self, function) self.interpreter = interpreter
def call(self, args_list, stack, stack_base, context): safe_args = self.interpreter.do_eager_thunks(args_list) return LambdaFunction.call(self, safe_args, stack, stack_base, context)
def run(self): sw_private = self.ciel_runtime.await_message("start_task") self.lazy_derefs = set() self.continuation = None self.result = None if "cont" in sw_private: self.continuation = self.unpickle_ref(sw_private["cont"]) else: self.continuation = self.start_sw_script(sw_private["swfile_ref"], sw_private["start_args"], sw_private["start_env"]) self.continuation.context.restart() task_context = TaskContext(self.continuation.context, self) task_context.bind_tasklocal_identifier( "spawn", LambdaFunction(lambda x: self.spawn_func(x[0], x[1]))) task_context.bind_tasklocal_identifier( "spawn_exec", LambdaFunction(lambda x: self.spawn_exec_func(x[0], x[1], x[2]))) task_context.bind_tasklocal_identifier( "spawn_other", LambdaFunction(lambda x: self.spawn_other(x[0], x[1]))) task_context.bind_tasklocal_identifier( "__star__", LambdaFunction(lambda x: self.lazy_dereference(x[0]))) task_context.bind_tasklocal_identifier( "int", SafeLambdaFunction(lambda x: int(x[0]), self)) task_context.bind_tasklocal_identifier( "str", SafeLambdaFunction(lambda x: str(x[0]), self)) task_context.bind_tasklocal_identifier( "range", SafeLambdaFunction(lambda x: range(*x), self)) task_context.bind_tasklocal_identifier( "len", SafeLambdaFunction(lambda x: len(x[0]), self)) task_context.bind_tasklocal_identifier( "has_key", SafeLambdaFunction(lambda x: x[1] in x[0], self)) task_context.bind_tasklocal_identifier( "get_key", SafeLambdaFunction(lambda x: x[0][x[1]] if x[1] in x[0] else x[2], self)) task_context.bind_tasklocal_identifier( "exec", LambdaFunction(lambda x: self.exec_func(x[0], x[1], x[2]))) task_context.bind_tasklocal_identifier( "package", LambdaFunction(lambda x: self.package_lookup(x[0]))) task_context.bind_tasklocal_identifier( "print", LambdaFunction( lambda x: sys.stdout.write("%s\n" % str(x[0])) or True)) visitor = StatementExecutorVisitor(task_context) try: result = visitor.visit(self.continuation.task_stmt, self.continuation.stack, 0) # The script finished successfully # XXX: This is for the unusual case that we have a task fragment that runs # to completion without returning anything. # Could maybe use an ErrorRef here, but this might not be erroneous if, # e.g. the interactive shell is used. if result is None: result = SWErrorReference('NO_RETURN_VALUE', 'null') self.write_output( 0, lambda fp: simplejson.dump( result, fp, cls=SWReferenceJSONEncoder)) except ExecutionInterruption: cont_output = self.get_fresh_output("cont") cont_ref = self.write_output( cont_output, lambda fp: pickle.dump(self.continuation, fp)) self.ciel_runtime.send_message( "tail_spawn", { "executor_name": "swi", "cont_ref": cont_ref, "small_task": True, "extra_dependencies": list(self.lazy_derefs) }) except RuntimeSkywritingError, rse: print >> sys.stderr, rse.message self.ciel_runtime.send_message("error", {"report": rse.message})