Server IP : 66.29.132.122 / Your IP : 18.217.146.66 Web Server : LiteSpeed System : Linux business142.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : admazpex ( 531) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/root/proc/self/root/proc/self/root/opt/hc_python/lib64/python3.8/site-packages/pip/_internal/utils/ |
Upload File : |
import functools from time import perf_counter, sleep from typing import Callable, TypeVar from pip._vendor.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