MCPcopy Index your code
hub / github.com/python/cpython / sleeping_retry

Function sleeping_retry

Lib/test/support/__init__.py:2724–2755  ·  view source on GitHub ↗

Wait strategy that applies exponential backoff. Run the loop body until "break" stops the loop. Sleep at each loop iteration, but not at the first iteration. The sleep delay is doubled at each iteration (up to *max_delay* seconds). See busy_retry() documentation for the parame

(timeout, err_msg=None, /,
                     *, init_delay=0.010, max_delay=1.0, error=True)

Source from the content-addressed store, hash-verified

2722
2723
2724def sleeping_retry(timeout, err_msg=None, /,
2725 *, init_delay=0.010, max_delay=1.0, error=True):
2726 """
2727 Wait strategy that applies exponential backoff.
2728
2729 Run the loop body until "break" stops the loop. Sleep at each loop
2730 iteration, but not at the first iteration. The sleep delay is doubled at
2731 each iteration (up to *max_delay* seconds).
2732
2733 See busy_retry() documentation for the parameters usage.
2734
2735 Example raising an exception after SHORT_TIMEOUT seconds:
2736
2737 for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
2738 if check():
2739 break
2740
2741 Example of error=False usage:
2742
2743 for _ in support.sleeping_retry(support.SHORT_TIMEOUT, error=False):
2744 if check():
2745 break
2746 else:
2747 raise RuntimeError('my custom error')
2748 """
2749
2750 delay = init_delay
2751 for _ in busy_retry(timeout, err_msg, error=error):
2752 yield
2753
2754 time.sleep(delay)
2755 delay = min(delay * 2, max_delay)
2756
2757
2758class Stopwatch:

Callers 1

wait_processFunction · 0.85

Calls 2

busy_retryFunction · 0.85
sleepMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…