Skip to content

Commit

Permalink
retry function: allowing set exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
semio committed Feb 5, 2020
1 parent 49922de commit dff8632
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ddf_utils/factory/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from requests import Request
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
from requests.exceptions import ChunkedEncodingError
from tqdm import tqdm


Expand All @@ -34,7 +35,7 @@ def requests_retry_session(
return session


def retry(times=5, backoff=0.5):
def retry(times=5, backoff=0.5, exceptions=(Exception)):
"""general wrapper to retry things"""
def wrapper(func):
@wraps(func)
Expand All @@ -46,7 +47,7 @@ def newfunc(*args, **kwargs):
res = func(*args, **kwargs)
except KeyboardInterrupt:
raise
except Exception as e:
except exceptions as e:
ttimes = ttimes - 1
if ttimes == 0:
raise
Expand Down Expand Up @@ -88,7 +89,7 @@ def get_file_size(request, session_):
response.raise_for_status()
return int(response.headers['Content-length'])

@retry(times=retry_times, backoff=backoff)
@retry(times=retry_times, backoff=backoff, exceptions=(Exception, ChunkedEncodingError))
def run(request, session_, out_file_, resume_, file_size):
if osp.exists(out_file_) and resume_:
first_byte = osp.getsize(out_file_)
Expand Down

0 comments on commit dff8632

Please sign in to comment.