Fix memory exhaustion when downloading large files #869
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes issue #754 where the Kaggle API would exhaust system memory when downloading large datasets.
Problem
The HTTP client was not using
stream=Truewhen making requests for file downloads. This caused the entire file content to be loaded into memory before being written to disk, making the system unstable when downloading large datasets.Solution
KaggleHttpClient.call()to detect file download response types (FileDownloadandHttpRedirect)stream=True) for these response typesdownload_file()method already usesresponse.iter_content()for chunked reading, which now works properly with streaming enabledChanges
src/kagglesdk/kaggle_http_client.py
FileDownloadandHttpRedirecttypesstream=Truein request settings for file downloadspyproject.toml
kagglesdkfrom dependencies listkagglesdksource code is insrc/kagglesdk/and should use local code during editable install, not pull from PyPIImpact
This fix improves memory usage for:
competition_download_file,competition_download_files)dataset_download_file,dataset_download_files)model_instance_version_download)kernels_output)competition_leaderboard_download)Testing
kaggle competitions listworks correctlyFixes Shouldn't API client pass
stream = Trueto therequestswhen downloading datasets? #754