Skip to content

Commit

Permalink
Retry all requests timeouts (#7256)
Browse files Browse the repository at this point in the history
retry all requests timeouts
  • Loading branch information
lhoestq authored Oct 28, 2024
1 parent a9c610f commit 444ce83
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/datasets/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ def dataset_module_factory(
e.__cause__,
(
OfflineModeIsEnabled,
requests.exceptions.ConnectTimeout,
requests.exceptions.Timeout,
requests.exceptions.ConnectionError,
),
):
Expand All @@ -1624,7 +1624,7 @@ def dataset_module_factory(
).sha
except (
OfflineModeIsEnabled,
requests.exceptions.ConnectTimeout,
requests.exceptions.Timeout,
requests.exceptions.ConnectionError,
) as e:
raise ConnectionError(f"Couldn't reach '{path}' on the Hub ({e.__class__.__name__})") from e
Expand Down
2 changes: 1 addition & 1 deletion src/datasets/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,8 @@ def read_with_retries(*args, **kwargs):
except (
aiohttp.client_exceptions.ClientError,
asyncio.TimeoutError,
requests.exceptions.ConnectTimeout,
requests.exceptions.ConnectionError,
requests.exceptions.Timeout,
) as err:
disconnect_err = err
logger.warning(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_offline_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def test_offline_with_timeout():
with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT):
with pytest.raises(RequestWouldHangIndefinitelyError):
requests.request("GET", "https://huggingface.co")
with pytest.raises(requests.exceptions.ConnectTimeout):
with pytest.raises(requests.exceptions.Timeout):
requests.request("GET", "https://huggingface.co", timeout=1.0)
# old versions of `huggingface_hub` don't have timeouts by default and don't allow to set timeouts in HfFileSystem
if version.parse(huggingface_hub.__version__) >= version.parse("0.23.0"):
with pytest.raises(requests.exceptions.ConnectTimeout), NamedTemporaryFile() as temp_file:
with pytest.raises(requests.exceptions.Timeout), NamedTemporaryFile() as temp_file:
fsspec_get("hf://dummy", temp_file=temp_file)


Expand Down

0 comments on commit 444ce83

Please sign in to comment.