Skip to content

Commit

Permalink
Set default timeout in download.stream_file to 10 seconds, and allo…
Browse files Browse the repository at this point in the history
…w to override value
  • Loading branch information
benoit74 committed Nov 22, 2024
1 parent 5f92462 commit 3a9fe52
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add `filesystem.validate_folder_writable` to check if a folder can be written to #200

### Fixed

- Set default timeout in `download.stream_file` to 10 seconds, and allow to override value

## [4.0.0] - 2024-08-05

### Added
Expand Down
4 changes: 4 additions & 0 deletions src/zimscraperlib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@
ILLUSTRATIONS_METADATA_RE = re.compile(
r"^Illustration_(?P<height>\d+)x(?P<width>\d+)@(?P<scale>\d+)$"
)

# default timeout to get responses from upstream when doing web requests ; this is not
# the total time it gets to download the whole resource
DEFAULT_WEB_REQUESTS_TIMEOUT = 10
3 changes: 3 additions & 0 deletions src/zimscraperlib/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import yt_dlp as youtube_dl

from zimscraperlib import logger
from zimscraperlib.constants import DEFAULT_WEB_REQUESTS_TIMEOUT


class YoutubeDownloader:
Expand Down Expand Up @@ -181,6 +182,7 @@ def stream_file(
max_retries: int | None = 5,
headers: dict[str, str] | None = None,
session: requests.Session | None = None,
timeout: int | None = DEFAULT_WEB_REQUESTS_TIMEOUT,
*,
only_first_block: bool | None = False,
) -> tuple[int, requests.structures.CaseInsensitiveDict[str]]:
Expand Down Expand Up @@ -208,6 +210,7 @@ def stream_file(
stream=True,
proxies=proxies,
headers=headers,
timeout=timeout,
)
resp.raise_for_status()

Expand Down

0 comments on commit 3a9fe52

Please sign in to comment.