Skip to content

Commit 65458a5

Browse files
authored
ci: Add retry option to download data to avoid failures (#1721)
1 parent 2911499 commit 65458a5

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

scripts/download_data.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1+
import sys
2+
import time
3+
14
import bokeh
25
from packaging.version import Version
36

7+
8+
def retry(func, *args, **kwargs):
9+
for i in range(5):
10+
try:
11+
return func(*args, **kwargs)
12+
except Exception as e:
13+
wait = 10 * 2**i
14+
print(f'Attempt {i + 1} failed: {e}. Retrying in {wait}s...', file=sys.stderr)
15+
time.sleep(wait)
16+
return func(*args, **kwargs)
17+
18+
419
if Version(bokeh.__version__).release < (3, 5, 0):
520
import bokeh.sampledata
621

7-
bokeh.sampledata.download()
22+
retry(bokeh.sampledata.download)
823
print('bokeh data downloaded.')
924

1025
try:
1126
import pooch # noqa: F401
1227
import scipy # noqa: F401
1328
import xarray as xr
1429

15-
xr.tutorial.open_dataset('air_temperature')
16-
xr.tutorial.open_dataset('rasm')
30+
retry(xr.tutorial.open_dataset, 'air_temperature')
31+
retry(xr.tutorial.open_dataset, 'rasm', decode_times=False)
1732
print('xarray data downloaded.')
1833
except ModuleNotFoundError as e:
1934
print(f'ModuleNotFoundError when attempting to download xarray datasets : {e}')

0 commit comments

Comments
 (0)