From a81ab5e26b875224f314be0841c7cdb4d1ce81c8 Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Tue, 25 Feb 2020 19:52:40 +0700 Subject: [PATCH] gdrive: do not import pydrive2 on module load (#3399) --- dvc/remote/gdrive.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dvc/remote/gdrive.py b/dvc/remote/gdrive.py index fe115d2978..3691f87bc9 100644 --- a/dvc/remote/gdrive.py +++ b/dvc/remote/gdrive.py @@ -39,16 +39,18 @@ def __init__(self, path): def gdrive_retry(func): - from pydrive2.files import ApiRequestError - retry_re = re.compile(r"HttpError (403|500|502|503|504)") + def should_retry(exc): + from pydrive2.files import ApiRequestError + + return isinstance(exc, ApiRequestError) and retry_re.search(str(exc)) + # 15 tries, start at 0.5s, multiply by golden ratio, cap at 20s return retry( 15, timeout=lambda a: min(0.5 * 1.618 ** a, 20), - errors=ApiRequestError, - filter_errors=lambda exc: retry_re.search(str(exc)), + filter_errors=should_retry, )(func)