[docs]classRetryCheckRunner:""" A RetryCheckRunner is an object responsible for running retry checks over the lifetime of a request. Unlike the checks or the retry context, the runner persists between retries. It can therefore implement special logic for checks like "only try this check once". Its primary responsibility is to answer the question "should_retry(context)?" with a boolean. It takes as its input a list of checks. Checks may be paired with flags to indicate their configuration options. When not paired with flags, the flags are taken to be "NONE". Supported flags: ``RUN_ONCE`` The check will run at most once for a given request. Once it has run, it is recorded as "has_run" and will not be run again on that request. """# check configs: a list of pairs, (check, flags)# a check without flags is assumed to have flags=NONEdef__init__(self,checks:t.Iterable[RetryCheck])->None:self._checks:list[RetryCheck]=[]self._check_data:dict[RetryCheck,dict[str,t.Any]]={}forcheckinchecks:self._checks.append(check)self._check_data[check]={}defshould_retry(self,context:RetryContext)->bool:forcheckinself._checks:flags=getattr(check,"_retry_check_flags",RetryCheckFlags.NONE)ifflags&RetryCheckFlags.RUN_ONCE:ifself._check_data[check].get("has_run"):continueelse:self._check_data[check]["has_run"]=Trueresult=check(context)log.debug(# try to get name but don't fail if it's not a function..."ran retry check (%s) => %s",getattr(check,"__name__",check),result)ifresultisRetryCheckResult.no_decision:continueelifresultisRetryCheckResult.do_not_retry:returnFalseelse:returnTrue# fallthrough: don't retry any request which isn't marked for retryreturnFalse