Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid loading entire files into memory when downloading from ESGF #2434

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion esmvalcore/esgf/_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,10 @@ def _download(self, local_file, url):
cert=get_credentials())
response.raise_for_status()
with tmp_file.open("wb") as file:
for chunk in response.iter_content(chunk_size=None):
# Specify chunk_size to avoid
# https://github.com/psf/requests/issues/5536
megabyte = 2**20
for chunk in response.iter_content(chunk_size=megabyte):
if hasher is not None:
hasher.update(chunk)
file.write(chunk)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/esgf/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def test_single_download(mocker, tmp_path, checksum):
# We checked for a valid response
response.raise_for_status.assert_called_once()
# And requested a reasonable chunk size
response.iter_content.assert_called_with(chunk_size=None)
response.iter_content.assert_called_with(chunk_size=2**20)


def test_download_skip_existing(tmp_path, caplog):
Expand Down