def METHOD_NAME(cmd, *args, **kwargs):
    timeout = kwargs.pop("timeout", None)
    kwargs["stdout"] = subprocess.PIPE
    kwargs["stderr"] = subprocess.STDOUT
    cmdr = " ".join(map(repr, cmd))
    try:
        logger.debug(f"subprocess.Popen({cmdr, args, kwargs})")
        p = subprocess.Popen(cmd, *args, **kwargs)
    except Exception as e:
        logger.error("subprocess failed {}".format(cmdr), exc_info=True)
        raise
    stdout_data, stderr_data = None, None
    try:
        if timeout:
            stdout_data, stderr_data = p.communicate(timeout=timeout)
        else:
            stdout_data, stderr_data = p.communicate()
    except subprocess.TimeoutExpired as te:
        logger.error("subprocess timed out {}".format(cmdr), exc_info=True)
        stdout_data, stderr_data = _getio(p, stdout_data, stderr_data)
        if stdout_data:
            sys.stderr.write("output from {}:\n{}\n\n".format(cmdr, stdout_data))
        if stderr_data:
            sys.stderr.write("stderr from {}:\n{}\n\n".format(cmdr, stderr_data))
        raise
    except Exception as e:
        logger.error("subprocess exception {}".format(cmdr), exc_info=True)
        stdout_data, stderr_data = _getio(p, stdout_data, stderr_data)
        if stdout_data:
            sys.stderr.write("output from {}:\n{}\n\n".format(cmdr, stdout_data))
        if stderr_data:
            sys.stderr.write("stderr from {}:\n{}\n\n".format(cmdr, stderr_data))
        raise
    if p.returncode != 0:
        logger.error("cmd failed ({}) {}".format(p.returncode, cmdr))
        stdout_data, stderr_data = _getio(p, stdout_data, stderr_data)
        if stdout_data:
            sys.stderr.write("output from {}:\n{}\n\n".format(cmdr, stdout_data))
        if stderr_data:
            sys.stderr.write("stderr from {}:\n{}\n\n".format(cmdr, stderr_data))
        raise Exception("error: cmd failed: {}".format(cmdr))
    if logger.isEnabledFor(logging.DEBUG):
        logger.debug(
            "cmd success: %s\n%s\n%s\n",
            cmdr,
            maybedecode(stdout_data),
            maybedecode(stderr_data),
        )