Skip to content

Commit 6235e93

Browse files
authored
Merge pull request kivy#2291 from obfusk/patch-9
download_file: show error + exponential sleep
2 parents f2946aa + 0039087 commit 6235e93

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pythonforandroid/recipe.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,17 @@ def report_hook(index, blksize, size):
191191

192192
# Download item with multiple attempts (for bad connections):
193193
attempts = 0
194+
seconds = 1
194195
while True:
195196
try:
196197
urlretrieve(url, target, report_hook)
197-
except OSError:
198+
except OSError as e:
198199
attempts += 1
199200
if attempts >= 5:
200201
raise
201-
stdout.write('Download failed retrying in a second...')
202-
time.sleep(1)
202+
stdout.write('Download failed: {}; retrying in {} second(s)...'.format(e, seconds))
203+
time.sleep(seconds)
204+
seconds *= 2
203205
continue
204206
break
205207
return target

tests/test_recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def test_download_file_scheme_https_oserror(self):
179179
retry = 5
180180
expected_call_args_list = [mock.call(url, filename, mock.ANY)] * retry
181181
assert m_urlretrieve.call_args_list == expected_call_args_list
182-
expected_call_args_list = [mock.call(1)] * (retry - 1)
182+
expected_call_args_list = [mock.call(2**i) for i in range(retry - 1)]
183183
assert m_sleep.call_args_list == expected_call_args_list
184184

185185

0 commit comments

Comments
 (0)