<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _run_with_retries(cmd, max_retries=CMD_RETRY_COUNT, retry_exitcodes=(1,), retry_message="", cmd_env=None):
 """Run a command and retry until success or max_retries is reached. :param: cmd: str: The apt command to run. :param: max_retries: int: The number of retries to attempt on a fatal command. Defaults to CMD_RETRY_COUNT. :param: retry_exitcodes: tuple: Optional additional exit codes to retry. Defaults to retry on exit code 1. :param: retry_message: str: Optional log prefix emitted during retries. :param: cmd_env: dict: Environment variables to add to the command run. """


    env = None
    kwargs = {}
    if cmd_env:
        env = os.environ.copy()
        env.update(cmd_env)
        kwargs['env'] = env

    if not retry_message:
        retry_message = "Failed executing '{}'".format(" ".join(cmd))
    retry_message += ". Will retry in {} seconds".format(CMD_RETRY_DELAY)

    retry_count = 0
    result = None

    retry_results = (None,) + retry_exitcodes
    while result in retry_results:
        try:
            # result = subprocess.check_call(cmd, env=env)
            result = subprocess.check_call(cmd, **kwargs)
        except subprocess.CalledProcessError as e:
            retry_count = retry_count + 1
            if retry_count > max_retries:
                raise
            result = e.returncode
            log(retry_message)
            time.sleep(CMD_RETRY_DELAY)