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)
| 2722 | |
| 2723 | |
| 2724 | def 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 | |
| 2758 | class Stopwatch: |
no test coverage detected
searching dependent graphs…