def processWait()

in benchmarking/utils/subprocess_with_logger.py [0:0]


def processWait(processAndTimeout, **kwargs):
    silent = kwargs.get("silent", False)
    try:
        ps, t = processAndTimeout
        process_key = ""
        if "process_key" in kwargs:
            process_key = kwargs["process_key"]
        log_output = False
        if "log_output" in kwargs:
            log_output = kwargs["log_output"]
        ignore_status = False
        if "ignore_status" in kwargs:
            ignore_status = kwargs["ignore_status"]
        patterns = []
        if "patterns" in kwargs:
            patterns = kwargs["patterns"]
        output, match = _getOutput(ps, patterns, process_key=process_key)
        ps.stdout.close()
        if match:
            # if the process is terminated by mathing output,
            # assume the process is executed successfully
            ps.terminate()
            status = 0
        else:
            # wait for the process to terminate or for a kill request
            while not getRunKilled():
                try:
                    status = ps.wait(timeout=15.0)
                    break
                except subprocess.TimeoutExpired:
                    pass
            # check if we exitted loop due to a timeout request
            if getRunKilled():
                getLogger().info("Process was killed at user request")
                ps.terminate()
                status = 0
        if t is not None:
            t.cancel()
        if log_output or (status != 0 and not ignore_status):
            if status != 0 and not ignore_status:
                if not silent:
                    getLogger().info("Process exited with status: {}".format(status))
                setRunStatus(1, key=process_key)
            if "filter" in kwargs:
                output = _filterOutput(output, kwargs["filter"])
            if not silent:
                getLogger().info(
                    "\n\nProgram Output:\n{}\n{}\n{}\n".format(
                        "=" * 80, "\n".join(output), "=" * 80
                    )
                )
        if status == 0 or ignore_status:
            setRunStatus(0, key=process_key)
            return output, None
        else:
            setRunStatus(1, key=process_key)
            return [], "\n".join(output)
    except subprocess.CalledProcessError as e:
        err_output = e.output.decode("utf-8", errors="replace")
        getLogger().error("Command failed: {}".format(err_output))
    except Exception:
        err_output = "{}".format(sys.exc_info()[0])
        getLogger().error("Unknown exception {}".format(sys.exc_info()[0]))
    return [], err_output