PHP 8.2.30
Preview: retry.py Size: 1.43 KB
/opt/hc_python/lib/python3.12/site-packages/pip/_internal/utils/retry.py

from __future__ import annotations

import functools
from time import perf_counter, sleep
from typing import TYPE_CHECKING, Callable, TypeVar

if TYPE_CHECKING:
    from typing_extensions import ParamSpec

    T = TypeVar("T")
    P = ParamSpec("P")


def retry(
    wait: float, stop_after_delay: float
) -> Callable[[Callable[P, T]], Callable[P, T]]:
    """Decorator to automatically retry a function on error.

    If the function raises, the function is recalled with the same arguments
    until it returns or the time limit is reached. When the time limit is
    surpassed, the last exception raised is reraised.

    :param wait: The time to wait after an error before retrying, in seconds.
    :param stop_after_delay: The time limit after which retries will cease,
        in seconds.
    """

    def wrapper(func: Callable[P, T]) -> Callable[P, T]:

        @functools.wraps(func)
        def retry_wrapped(*args: P.args, **kwargs: P.kwargs) -> T:
            # The performance counter is monotonic on all platforms we care
            # about and has much better resolution than time.monotonic().
            start_time = perf_counter()
            while True:
                try:
                    return func(*args, **kwargs)
                except Exception:
                    if perf_counter() - start_time > stop_after_delay:
                        raise
                    sleep(wait)

        return retry_wrapped

    return wrapper

Directory Contents

Dirs: 1 × Files: 25

Name Size Perms Modified Actions
- drwxr-xr-x 2025-12-03 08:02:41
Edit Download
1.64 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
2.46 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
6.47 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
241 B lrw-r--r-- 2025-12-03 08:02:41
Edit Download
3.61 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
3.13 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
2.40 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
3.25 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
5.37 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
689 B lrw-r--r-- 2025-12-03 08:02:41
Edit Download
3.64 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
4.88 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
11.82 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
22.83 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
1.56 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
1.43 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
8.77 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
9.09 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
12.67 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
1.56 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
3.37 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
4.36 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
3.27 KB lrw-r--r-- 2025-12-03 08:02:41
Edit Download
1015 B lrw-r--r-- 2025-12-03 08:02:41
Edit Download
0 B lrw-r--r-- 2025-12-03 08:02:41
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).