huggingface / huggingface_hub

The official Python client for the Huggingface Hub.
https://huggingface.co/docs/huggingface_hub
Apache License 2.0
1.83k stars 471 forks source link

Fix progress bar not always closed in file_download.py #2308

Closed Wauplin closed 1 month ago

Wauplin commented 1 month ago

When downloading files in file_download.py, we use a progress bar. This progress bar can be either passed by the user or we create a classic tqdm bar (see update in https://github.com/huggingface/huggingface_hub/pull/2143).

As @cbensimon noticed, the progress bar is not correctly closed when an error occurs or when hf_transfer is used. This PR fixes this by using a context manager. The progress bar is now always closed if created internally. When passed by the user, the progress bar is not closed as it is a the user's discretion to manage it.

Better to review with "hide whitespace" checked.

HuggingFaceDocBuilderDev commented 1 month ago

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Wauplin commented 1 month ago

Thanks for the review!