Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Commit

Permalink
Retry failed downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Oct 4, 2015
1 parent ff2f826 commit 705e4b0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion wcsaxes/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""Downloads the FITS files that are used in image testing and for building documentation.
"""

import time

from astropy.utils.data import download_file
from astropy.io import fits

Expand All @@ -11,13 +14,24 @@
'fetch_bolocam_hdu',
]

MAX_RETRIES = 10
TIME_BETWEEN_RETRIES = 5
URL = 'http://data.astropy.org/'


def fetch_hdu(filename, cache=True):
"""Download a FITS file to the cache and open HDU 0.
"""
path = download_file(URL + filename, cache=cache, timeout=30)
for retry in range(MAX_RETRIES):
try:
path = download_file(URL + filename, cache=cache, timeout=30)
except:
if retry == MAX_RETRIES - 1:
raise
else:
time.sleep(TIME_BETWEEN_RETRIES)
else:
break
return fits.open(path)[0]


Expand Down

0 comments on commit 705e4b0

Please sign in to comment.