Skip to content

Commit f5e4823

Browse files
authored
Merge pull request #722 from bioimage-io/dev
add BIOIMAGEIO_HTTP_TIMEOUT env var
2 parents 9856dc5 + a907095 commit f5e4823

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ In this file we log both:
1010

1111
This changelog includes implementation details and my reference the [changes to the Resource Description Format](#changes-to-the-resource-description-format), e.g. in entry [bioimageio.spec 0.5.2](#bioimageiospec-052).
1212

13+
#### bioimageio.spec 0.5.5.6 (planned; not yet released)
14+
15+
- Add BIOIMAGEIO_HTTP_TIMEOUT environment variable to adjust timeout for http requests.
16+
1317
#### bioimageio.spec 0.5.5.5
1418

1519
- use OS specific conda command to fix conda subprocess issues

src/bioimageio/spec/_internal/_settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def _expand_user(cls, value: Path):
5959
2. Generate a new token at https://bioimage.io/#/api?tab=hypha-rpc
6060
"""
6161

62+
http_timeout: float = 10.0
63+
"""Timeout in seconds for http requests."""
64+
6265
id_map: str = (
6366
"https://uk1s3.embassy.ebi.ac.uk/public-datasets/bioimage.io/id_map.json"
6467
)

src/bioimageio/spec/_internal/field_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def validate_github_user(
7777
r = httpx.get(
7878
f"https://api.github.com/users/{username}",
7979
auth=settings.github_auth,
80-
timeout=3,
80+
timeout=settings.http_timeout,
8181
)
8282
except httpx.TimeoutException:
8383
issue_warning(

src/bioimageio/spec/_internal/io.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,12 @@ def _fetch_url(
760760
elif settings.CI:
761761
headers["User-Agent"] = "ci"
762762

763-
r = httpx.get(str(source), follow_redirects=True, headers=headers)
763+
r = httpx.get(
764+
str(source),
765+
follow_redirects=True,
766+
headers=headers,
767+
timeout=settings.http_timeout,
768+
)
764769
_ = r.raise_for_status()
765770

766771
# set progressbar.total

src/bioimageio/spec/_internal/io_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ def _get_id_map_impl(url: str) -> Dict[str, LightHttpFileDescr]:
245245
if not isinstance(url, str) or "/" not in url:
246246
logger.opt(depth=1).error("invalid id map url: {}", url)
247247
try:
248-
id_map_raw: Any = httpx.get(url, timeout=10, follow_redirects=True).json()
248+
id_map_raw: Any = httpx.get(
249+
url, timeout=settings.http_timeout, follow_redirects=True
250+
).json()
249251
except Exception as e:
250252
logger.opt(depth=1).error("failed to get {}: {}", url, e)
251253
return {}

src/bioimageio/spec/_internal/url.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
from typing_extensions import Literal, assert_never
99

1010
from . import warning_levels
11+
from ._settings import settings
1112
from .field_warning import issue_warning
1213
from .root_url import RootHttpUrl
1314
from .validation_context import get_validation_context
1415

1516

1617
def _validate_url(url: Union[str, pydantic.HttpUrl]) -> pydantic.HttpUrl:
17-
return _validate_url_impl(url, request_mode="head")
18+
return _validate_url_impl(url, request_mode="head", timeout=settings.http_timeout)
1819

1920

2021
_KNOWN_VALID_URLS = ("https://zenodo.org/records/3446812/files/unet2d_weights.torch",)
@@ -24,7 +25,7 @@ def _validate_url(url: Union[str, pydantic.HttpUrl]) -> pydantic.HttpUrl:
2425
def _validate_url_impl(
2526
url: Union[str, pydantic.HttpUrl],
2627
request_mode: Literal["head", "get_stream", "get"],
27-
timeout: int = 3,
28+
timeout: float,
2829
) -> pydantic.HttpUrl:
2930
url = str(url)
3031
context = get_validation_context()

0 commit comments

Comments
 (0)