MCPcopy
hub / github.com/urllib3/urllib3 / get_backoff_time

Method get_backoff_time

src/urllib3/util/retry.py:309–326  ·  view source on GitHub ↗

Formula for computing the current backoff :rtype: float

(self)

Source from the content-addressed store, hash-verified

307 return new_retries
308
309 def get_backoff_time(self) -> float:
310 """Formula for computing the current backoff
311
312 :rtype: float
313 """
314 # We want to consider only the last consecutive errors sequence (Ignore redirects).
315 consecutive_errors_len = len(
316 list(
317 takewhile(lambda x: x.redirect_location is None, reversed(self.history))
318 )
319 )
320 if consecutive_errors_len <= 1:
321 return 0
322
323 backoff_value = self.backoff_factor * (2 ** (consecutive_errors_len - 1))
324 if self.backoff_jitter != 0.0:
325 backoff_value += random.random() * self.backoff_jitter
326 return float(max(0, min(self.backoff_max, backoff_value)))
327
328 def parse_retry_after(self, retry_after: str) -> float:
329 seconds: float

Callers 6

test_backoffMethod · 0.95
test_backoff_jitterMethod · 0.95
test_zero_backoffMethod · 0.95
_sleep_backoffMethod · 0.95

Calls

no outgoing calls

Tested by 5

test_backoffMethod · 0.76
test_backoff_jitterMethod · 0.76
test_zero_backoffMethod · 0.76