Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add download retries to deal better with connection hiccups during build #1574

Merged
merged 1 commit into from Jan 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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