Skip to content

Commit

Permalink
Merge pull request #1574 from JonasT/recipe-download-retries
Browse files Browse the repository at this point in the history
Add download retries to deal better with connection hiccups during build
  • Loading branch information
AndreMiras authored Jan 25, 2019
2 parents f2a18a8 + ed919d0 commit 0002847
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import fnmatch
from os import listdir, unlink, environ, mkdir, curdir, walk
from sys import stdout
import time
try:
from urlparse import urlparse
except ImportError:
Expand Down Expand Up @@ -145,7 +146,19 @@ def report_hook(index, blksize, size):
if exists(target):
unlink(target)

urlretrieve(url, target, report_hook)
# Download item with multiple attempts (for bad connections):
attempts = 0
while True:
try:
urlretrieve(url, target, report_hook)
except OSError as e:
attempts += 1
if attempts >= 5:
raise e
stdout.write('Download failed retrying in a second...')
time.sleep(1)
continue
break
return target
elif parsed_url.scheme in ('git', 'git+file', 'git+ssh', 'git+http', 'git+https'):
if isdir(target):
Expand Down

0 comments on commit 0002847

Please sign in to comment.