Ejemplo n.º 1
0
    def run(self):
        #TODO: handle errors here!!
        try:
            task = self.task

            cmd_args, stdin_file, stdout_file, stderr_file = task._prepare_command(
            )
            logging.info("Running app task %s.  Command line: %s." %
                         (self.task.name(), ' '.join(cmd_args)))
            if stdin_file is not None:
                logging.info("stdin redirected from %s" % stdin_file)
            if stdout_file is not None:
                logging.info("stdout redirected to %s" % stdout_file)
            if stderr_file is not None:
                logging.info("stderr redirected to %s" % stderr_file)

            if self.process is not None:
                raise Exception("Tried to run AppQueueEntry twice")

            stdin = stdout = stderr = None
            try:
                # Open the file if the path is not None
                stdin = openFile(stdin_file, 'r')
                stdout = openFile(stdout_file, 'w')
                stderr = openFile(stderr_file, 'w')

                logging.debug("Launching %s" % repr(cmd_args))
                #print "Starting a task"
                # launch the process

                exc = paths.lookup(cmd_args[0])
                if exc is not None:
                    # Use the binary we just looked up, otherwise
                    # use the OS's resolution mechanism
                    cmd_args[0] = exc
                try:
                    self.process = subprocess.Popen(
                        cmd_args,
                        stdin=stdin,
                        stdout=stdout,
                        stderr=stderr,
                        close_fds=True  # don't inherit any open files this
                        # process may have. TODO: might not
                        # work on windows
                    )
                except OSError, e:
                    self.failure_continuation(
                        self.task,
                        AppLaunchException(repr(self.task), cmd_args[0], e))
                    return False
            finally:
                # Don't need just-opened file descriptors in this process now
                for f in (stdin, stderr, stdout):
                    if f is not None:
                        f.close()
            self.task.started_callback()
            return True
        except Exception, e:
            self.failure_continuation(self.task, e)
            return False
Ejemplo n.º 2
0
    def run(self):
        task = self.task

        cmd_args, stdin_file, stdout_file, stderr_file = task._prepare_command()
        if self.process is not None:
            raise Exception("Tried to run AppQueueEntry twice")
       
        # Open the file if the path is not None
        openFile = lambda fp, mode: fp and open(fp, mode)
        stdin=openFile(stdin_file, 'r')
        stdout=openFile(stdout_file, 'w')
        stderr=openFile(stderr_file, 'w')

        logging.debug("Launching %s" % repr(cmd_args))
        #print "Starting a task"
        # launch the process
        
        exc = paths.lookup(cmd_args[0])
        if exc is not None:
            # Use the binary we just looked up, otherwise
            # use the OS's resolution mechanism
            cmd_args[0] = exc
        self.process = subprocess.Popen(cmd_args,
            stdin = stdin, stdout = stdout,  
            stderr = stderr,
            close_fds=True # don't inherit any open files this
                           # process may have. TODO: might not
                           # work on windows
            )
        # Don't need just-opened file descriptors in this process now
        for f in (stdin, stderr, stdout):
            if f is not None:
                f.close()
        self.task.started_callback()
Ejemplo n.º 3
0
 def run(self):
     #TODO: handle errors here!!
     try: 
         task = self.task
 
         cmd_args, stdin_file, stdout_file, stderr_file = task._prepare_command()
         logging.info("Running app task %s.  Command line: %s." % (self.task.name(), 
                                 ' '.join(cmd_args)))
         if stdin_file is not None:
             logging.info("stdin redirected from %s" % stdin_file)
         if stdout_file is not None:
             logging.info("stdout redirected to %s" % stdout_file)
         if stderr_file is not None:
             logging.info("stderr redirected to %s" % stderr_file)
             
         if self.process is not None:
             raise Exception("Tried to run AppQueueEntry twice")
        
         stdin = stdout = stderr = None
         try:
             # Open the file if the path is not None
             stdin=openFile(stdin_file, 'r')
             stdout=openFile(stdout_file, 'w')
             stderr=openFile(stderr_file, 'w')
     
             logging.debug("Launching %s" % repr(cmd_args))
             #print "Starting a task"
             # launch the process
             
             exc = paths.lookup(cmd_args[0])
             if exc is not None:
                 # Use the binary we just looked up, otherwise
                 # use the OS's resolution mechanism
                 cmd_args[0] = exc
             try:
                 self.process = subprocess.Popen(cmd_args,
                     stdin = stdin, stdout = stdout,  
                     stderr = stderr,
                     close_fds=True # don't inherit any open files this
                                    # process may have. TODO: might not
                                    # work on windows
                     )
             except OSError, e:
                 self.failure_continuation(self.task, AppLaunchException(repr(self.task),                       
                                     cmd_args[0], e))
                 return False
         finally:
             # Don't need just-opened file descriptors in this process now
             for f in (stdin, stderr, stdout):
                 if f is not None:
                     f.close()
         self.task.started_callback()
         return True
     except Exception, e:
         self.failure_continuation(self.task, e)
         return False
Ejemplo n.º 4
0
    def run(self):
        task = self.task

        cmd_args, stdin_file, stdout_file, stderr_file = task._prepare_command(
        )
        if self.process is not None:
            raise Exception("Tried to run AppQueueEntry twice")

        # Open the file if the path is not None
        openFile = lambda fp, mode: fp and open(fp, mode)
        stdin = openFile(stdin_file, 'r')
        stdout = openFile(stdout_file, 'w')
        stderr = openFile(stderr_file, 'w')

        logging.debug("Launching %s" % repr(cmd_args))
        #print "Starting a task"
        # launch the process

        exc = paths.lookup(cmd_args[0])
        if exc is not None:
            # Use the binary we just looked up, otherwise
            # use the OS's resolution mechanism
            cmd_args[0] = exc
        self.process = subprocess.Popen(
            cmd_args,
            stdin=stdin,
            stdout=stdout,
            stderr=stderr,
            close_fds=True  # don't inherit any open files this
            # process may have. TODO: might not
            # work on windows
        )
        # Don't need just-opened file descriptors in this process now
        for f in (stdin, stderr, stdout):
            if f is not None:
                f.close()
        self.task.started_callback()