Ejemplo n.º 1
0
Archivo: task.py Proyecto: ms705/ciel
    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("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])))
    
        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 as e:

            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)
                                                          }
                                           )
Ejemplo n.º 2
0
 def interpret(self):
     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("__star__", LambdaFunction(lambda x: self.lazy_dereference(x[0])))
     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("ref", LambdaFunction(lambda x: self.make_reference(x)))
     #task_context.bind_tasklocal_identifier("is_future", LambdaFunction(lambda x: self.is_future(x[0])))
     #task_context.bind_tasklocal_identifier("is_error", LambdaFunction(lambda x: self.is_error(x[0])))
     #task_context.bind_tasklocal_identifier("abort", LambdaFunction(lambda x: self.abort_production(x[0])))
     #task_context.bind_tasklocal_identifier("task_details", LambdaFunction(lambda x: self.get_task_details(x[0])))
     #task_context.bind_tasklocal_identifier("select", LambdaFunction(lambda x: self.select_func(x[0]) if len(x) == 1 else self.select_func(x[0], x[1])))
     visitor = StatementExecutorVisitor(task_context)
     
     try:
         self.result = visitor.visit(self.continuation.task_stmt, self.continuation.stack, 0)
         
         # 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 self.result is None:
             self.result = SWNullReference()
         
     except SelectException, se:
         
         local_select_group = se.select_group
         timeout = se.timeout
         
         select_group = map(self.continuation.resolve_tasklocal_reference_with_ref, local_select_group)
                     
         cont_task_id = self.create_spawned_task_name()
                     
         cont_task_descriptor = {'task_id': str(cont_task_id),
                                 'handler': 'swi',
                                 'dependencies': {},
                                 'select_group': select_group,
                                 'select_timeout': timeout,
                                 'expected_outputs': map(str, self.expected_outputs),
                                 'save_continuation': self.save_continuation}
         self.save_continuation = False
         self.spawn_list.append(SpawnListEntry(cont_task_id, cont_task_descriptor, self.continuation))
Ejemplo n.º 3
0
 def interpret(self):
     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("__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("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("ref", LambdaFunction(lambda x: self.make_reference(x)))
     #task_context.bind_tasklocal_identifier("is_future", LambdaFunction(lambda x: self.is_future(x[0])))
     #task_context.bind_tasklocal_identifier("is_error", LambdaFunction(lambda x: self.is_error(x[0])))
     #task_context.bind_tasklocal_identifier("abort", LambdaFunction(lambda x: self.abort_production(x[0])))
     #task_context.bind_tasklocal_identifier("task_details", LambdaFunction(lambda x: self.get_task_details(x[0])))
     #task_context.bind_tasklocal_identifier("select", LambdaFunction(lambda x: self.select_func(x[0]) if len(x) == 1 else self.select_func(x[0], x[1])))
     visitor = StatementExecutorVisitor(task_context)
     
     try:
         self.result = visitor.visit(self.continuation.task_stmt, self.continuation.stack, 0)
         
         # 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 self.result is None:
             self.result = SWErrorReference(self.expected_outputs[0], 'NO_RETURN_VALUE', 'null')
         
     except SelectException, se:
         
         local_select_group = se.select_group
         timeout = se.timeout
         
         select_group = map(self.continuation.resolve_tasklocal_reference_with_ref, local_select_group)
                     
         cont_task_id = self.create_spawned_task_name()
                     
         cont_task_descriptor = {'task_id': str(cont_task_id),
                                 'handler': 'swi',
                                 'dependencies': {},
                                 'select_group': select_group,
                                 'select_timeout': timeout,
                                 'expected_outputs': map(str, self.expected_outputs),
                                 'save_continuation': self.save_continuation}
         self.save_continuation = False
         self.spawn_list.append(SpawnListEntry(cont_task_id, cont_task_descriptor, self.continuation))