From 1411a7be9139b9b708e299f60e19ad0a68164ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Fri, 27 Mar 2026 08:21:48 +0100 Subject: [PATCH] ci: Add retry option to download data to avoid failures --- scripts/download_data.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/download_data.py b/scripts/download_data.py index dbbaff4ed..8bd973d42 100644 --- a/scripts/download_data.py +++ b/scripts/download_data.py @@ -1,10 +1,25 @@ +import sys +import time + import bokeh from packaging.version import Version + +def retry(func, *args, **kwargs): + for i in range(5): + try: + return func(*args, **kwargs) + except Exception as e: + wait = 10 * 2**i + print(f'Attempt {i + 1} failed: {e}. Retrying in {wait}s...', file=sys.stderr) + time.sleep(wait) + return func(*args, **kwargs) + + if Version(bokeh.__version__).release < (3, 5, 0): import bokeh.sampledata - bokeh.sampledata.download() + retry(bokeh.sampledata.download) print('bokeh data downloaded.') try: @@ -12,8 +27,8 @@ import scipy # noqa: F401 import xarray as xr - xr.tutorial.open_dataset('air_temperature') - xr.tutorial.open_dataset('rasm') + retry(xr.tutorial.open_dataset, 'air_temperature') + retry(xr.tutorial.open_dataset, 'rasm', decode_times=False) print('xarray data downloaded.') except ModuleNotFoundError as e: print(f'ModuleNotFoundError when attempting to download xarray datasets : {e}')