Skip to content

Commit ed919d0

Browse files
author
Jonas Thiem
committed
Add download retries to deal better with bad connection during build
1 parent 21bc8b8 commit ed919d0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pythonforandroid/recipe.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import fnmatch
1313
from os import listdir, unlink, environ, mkdir, curdir, walk
1414
from sys import stdout
15+
import time
1516
try:
1617
from urlparse import urlparse
1718
except ImportError:
@@ -145,7 +146,19 @@ def report_hook(index, blksize, size):
145146
if exists(target):
146147
unlink(target)
147148

148-
urlretrieve(url, target, report_hook)
149+
# Download item with multiple attempts (for bad connections):
150+
attempts = 0
151+
while True:
152+
try:
153+
urlretrieve(url, target, report_hook)
154+
except OSError as e:
155+
attempts += 1
156+
if attempts >= 5:
157+
raise e
158+
stdout.write('Download failed retrying in a second...')
159+
time.sleep(1)
160+
continue
161+
break
149162
return target
150163
elif parsed_url.scheme in ('git', 'git+file', 'git+ssh', 'git+http', 'git+https'):
151164
if isdir(target):

0 commit comments

Comments
 (0)