def _execute(self, args, output_filename, stdin,
                 hardtimelimit, softtimelimit, walltimelimit, memlimit,
                 cores, memory_nodes,
                 cgroup_values,
                 environments, workingDir, max_output_size):
        """
        This method executes the command line and waits for the termination of it,
        handling all setup and cleanup, but does not check whether arguments are valid.
        """

        def preParent():
            """Setup that is executed in the parent process immediately before the actual tool is started."""
            # start measurements
            energy_before = util.measure_energy()
            walltime_before = util.read_monotonic_time()
            return (walltime_before, energy_before)

        def postParent(preParent_result):
            """Cleanup that is executed in the parent process immediately after the actual tool terminated."""
            # finish measurements
            walltime_before, energy_before = preParent_result
            walltime = util.read_monotonic_time() - walltime_before
            energy = util.measure_energy(energy_before)
            return (walltime, energy)

        def preSubprocess():
            """Setup that is executed in the forked process before the actual tool is started."""
            os.setpgrp() # make subprocess to group-leader
            os.nice(5) # increase niceness of subprocess
            self._setup_ulimit_time_limit(hardtimelimit, cgroups)

        # preparations that are not time critical
        cgroups = self._setup_cgroups(cores, memlimit, memory_nodes, cgroup_values)
        base_dir, home_dir, temp_dir = self._setup_temp_dir()
        run_environment = self._setup_environment(environments, home_dir, temp_dir)
        outputFile = self._setup_output_file(output_filename, args)
        args = self._build_cmdline(args, env=run_environment)

        timelimitThread = None
        oomThread = None
        pid = None
        returnvalue = 0
        ru_child = None
        self._termination_reason = None

        throttle_check = systeminfo.CPUThrottleCheck(cores)
        swap_check = systeminfo.SwapCheck()

        logging.debug('Starting process.')

        try:
            pid, result_fn = self._start_execution(args=args,
                stdin=stdin, stdout=outputFile, stderr=outputFile,
                env=run_environment, cwd=workingDir,
                cgroups=cgroups,
                parent_setup_fn=preParent, child_setup_fn=preSubprocess,
                parent_cleanup_fn=postParent)

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

            timelimitThread = self._setup_cgroup_time_limit(
                hardtimelimit, softtimelimit, walltimelimit, cgroups, cores, pid)
            oomThread = self._setup_cgroup_memory_limit(memlimit, cgroups, pid)

            returnvalue, ru_child, (walltime, energy) = result_fn() # blocks until process has terminated

            result = {}
            result['walltime'] = walltime
            if energy:
                result['energy'] = energy

            # needs to come before cgroups.remove()
            self._get_cgroup_measurements(cgroups, ru_child, result)

        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 timelimitThread:
                timelimitThread.cancel()

            if oomThread:
                oomThread.cancel()

            # Kill all remaining processes if some managed to survive.
            # Because we send signals to all processes anyway we use the
            # internal function.
            cgroups.kill_all_tasks(self._kill_process0)

            # normally subprocess closes file, we do this again after all tasks terminated
            outputFile.close()

            logging.debug("Cleaning up cgroups.")
            cgroups.remove()

            self._cleanup_temp_dir(base_dir)

        # cleanup steps that are only relevant in case of success
        if throttle_check.has_throttled():
            logging.warning('CPU throttled itself during benchmarking due to overheating. '
                            'Benchmark results are unreliable!')
        if swap_check.has_swapped():
            logging.warning('System has swapped during benchmarking. '
                            'Benchmark results are unreliable!')

        _reduce_file_size_if_necessary(output_filename, max_output_size)

        if returnvalue not in [0,1]:
            _get_debug_output_after_crash(output_filename)

        result['exitcode'] = returnvalue
        if self._termination_reason:
            result['terminationreason'] = self._termination_reason
        elif memlimit and 'memory' in result and memlimit >= result['memory']:
            # The kernel does not always issue OOM notifications and thus the OOMHandler
            # does not always run even in case of OOM. We detect this there and report OOM.
            result['terminationreason'] = 'memory'

        return result
dataset/ETHPy150Open sosy-lab/benchexec/benchexec/runexecutor.py/RunExecutor._execute/swapped operands of `>=`