Skip to content

Add a default timeout to all requests, make it configurable#226

Open
amercader wants to merge 2 commits intomasterfrom
timeouts
Open

Add a default timeout to all requests, make it configurable#226
amercader wants to merge 2 commits intomasterfrom
timeouts

Conversation

@amercader
Copy link
Member

Make sure the the timeout parameter is passed to requests before making an HTTP request. By default we use (5,5) which means 5 seconds for connect and read timeouts.

I added a separate option for the read timeout as it is specially important in the streaming requests we use to load/dump datasets.

@wardi @EricSoroos what do you think of the default value? currently 5 seconds for both

Make sure the the `timeout` parameter is passed to requests before
making an HTTP request. By default we use (5,5) which means 5 seconds
for connect and read timeouts.
@EricSoroos
Copy link

LGTM, 5 seconds is a decent default, IIRC the read timeout is not for completion, just for byte gaps. I think it's going to be rarely set, but may be useful in some specific cases.

To avoid this warning:

```
  ckanapi/ckanapi/cli/load.py:307: SyntaxWarning: "\." is an invalid
  escape sequence. Such sequences will not work in the
    future. Did you mean "\\."? A raw string is also an option.
        new_name = re.sub('[0-9\.-]','',name)
```
f = requests.get(obj['image_display_url'], stream=True, timeout=REQUEST_TIMEOUT)
name,ext = obj['image_url'].rsplit('.',1) #reformulate image_url for new site
new_name = re.sub('[0-9\.-]','',name)
new_name = re.sub('[0-9.-]','',name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change make the sub do nothing. I think this is what was intended:

Suggested change
new_name = re.sub('[0-9.-]','',name)
new_name = re.sub(r'[0-9\.-]','',name)

@wardi
Copy link
Contributor

wardi commented Feb 20, 2026

How does this interact with someone setting the timeout via requests_kwargs?

files=None, requests_kwargs=None):

@wardi
Copy link
Contributor

wardi commented Feb 20, 2026

Setting a new default timeout of 5 seconds would be a breaking change. Calling datastore_search on a 1M row table will take longer than that just because of computing the total row count.

The default should either be really long or unset to minimize breaking existing users' code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants