Beispiel #1
0
    def execute_run(self,
                    args,
                    workingDir=None,
                    output_dir=None,
                    result_files_patterns=[]):
        """
        This method executes the command line and waits for the termination of it,
        handling all setup and cleanup.
        @param args: the command line to run
        @param workingDir: None or a directory which the execution should use as working directory
        @param output_dir: the directory where to write result files (required if result_files_pattern)
        @param result_files_patterns: a list of patterns of files to retrieve as result files
        """
        # preparations
        temp_dir = tempfile.mkdtemp(prefix="BenchExec_run_")

        pid = None
        returnvalue = 0

        logging.debug('Starting process.')

        try:
            pid, result_fn = self._start_execution(
                args=args,
                stdin=None,
                stdout=None,
                stderr=None,
                env=os.environ.copy(),
                cwd=workingDir,
                temp_dir=temp_dir,
                cgroups=Cgroup({}),
                output_dir=output_dir,
                result_files_patterns=result_files_patterns,
                child_setup_fn=lambda: None,
                parent_setup_fn=lambda: None,
                parent_cleanup_fn=id)

            with self.SUB_PROCESS_PIDS_LOCK:
                self.SUB_PROCESS_PIDS.add(pid)

            returnvalue, unused_ru_child, unused = result_fn(
            )  # blocks until process has terminated

        finally:
            # cleanup steps that need to get executed even in case of failure
            logging.debug('Process terminated, exit code %s.', returnvalue)

            with self.SUB_PROCESS_PIDS_LOCK:
                self.SUB_PROCESS_PIDS.discard(pid)

            logging.debug('Cleaning up temporary directory.')
            util.rmtree(temp_dir, onerror=util.log_rmtree_error)

        # cleanup steps that are only relevant in case of success
        return util.ProcessExitCode.from_raw(returnvalue)
    def execute_run(
        self,
        args,
        workingDir=None,  # noqa: N803 backwards-compatibility
        output_dir=None,
        result_files_patterns=[],
        rootDir=None,
        environ=None,
    ):
        """
        This method executes the command line and waits for the termination of it,
        handling all setup and cleanup.

        Note that this method does not expect to be interrupted by KeyboardInterrupt
        and does not guarantee proper cleanup if KeyboardInterrupt is raised!
        If this method runs on the main thread of your program,
        make sure to set a signal handler for signal.SIGINT that calls stop() instead.

        @param args: the command line to run
        @param rootDir: None or a root directory that contains all relevant files
            for starting a new process
        @param workingDir:
            None or a directory which the execution should use as working directory
        @param output_dir: the directory where to write result files
            (required if result_files_pattern)
        @param result_files_patterns:
            a list of patterns of files to retrieve as result files
        """
        # preparations
        temp_dir = None
        if rootDir is None:
            temp_dir = tempfile.mkdtemp(prefix="BenchExec_run_")
        if environ is None:
            environ = os.environ.copy()

        pid = None
        returnvalue = 0

        logging.debug("Starting process.")

        try:
            pid, result_fn = self._start_execution(
                args=args,
                stdin=None,
                stdout=None,
                stderr=None,
                env=environ,
                root_dir=rootDir,
                cwd=workingDir,
                temp_dir=temp_dir,
                cgroups=Cgroup({}),
                output_dir=output_dir,
                result_files_patterns=result_files_patterns,
                child_setup_fn=util.dummy_fn,
                parent_setup_fn=util.dummy_fn,
                parent_cleanup_fn=util.dummy_fn,
            )

            with self.SUB_PROCESS_PIDS_LOCK:
                self.SUB_PROCESS_PIDS.add(pid)

            # wait until process has terminated
            returnvalue, unused_ru_child, unused = result_fn()

        finally:
            # cleanup steps that need to get executed even in case of failure
            logging.debug("Process terminated, exit code %s.", returnvalue)

            with self.SUB_PROCESS_PIDS_LOCK:
                self.SUB_PROCESS_PIDS.discard(pid)

            if temp_dir is not None:
                logging.debug("Cleaning up temporary directory.")
                util.rmtree(temp_dir, onerror=util.log_rmtree_error)

        # cleanup steps that are only relevant in case of success
        return util.ProcessExitCode.from_raw(returnvalue)