Handle timeouts
CONTRIBUTOR
I never said the calls were hanging indefinitely, what we need is quite different - in the firewalled env with a network, there should be no network calls or they should fail instantly.

To make this work I suppose on top of this PR we need:
1. `DATASETS_OFFLINE` env var to force set timeout to 0 globally (or to 0.0001 if 0 has a special meaning of no timeout)
2. `DATASETS_OFFLINE` should guard against failing network calls and not fail the program if it has all the data it needs locally.

Bottom line - if the logic wants to check online if the local file matches online dataset name, let it go wild, but it should fail instantly, recover and use the local file - if one is specified explicitly or cache if there is one. And only if neither was found only then assert.

I hope this makes sense and is doable.

I have started on the same approach for transformers https://github.com/huggingface/transformers/pull/10407

Thank you, @lhoestq 
2021-02-26T17:52:35Z
https://github.com/huggingface/datasets/pull/1952#issuecomment-786798857
https://api.github.com/repos/huggingface/datasets/issues/1952
MDEyOklzc3VlQ29tbWVudDc4Njc5ODg1Nw==
https://api.github.com/repos/huggingface/datasets/issues/comments/786798857/reactions
2021-02-26T18:02:10Z
https://api.github.com/repos/huggingface/datasets/issues/comments/786798857
https://avatars.githubusercontent.com/u/10676103?v=4
https://api.github.com/users/stas00/events{/privacy}
https://api.github.com/users/stas00/followers
https://api.github.com/users/stas00/following{/other_user}
https://api.github.com/users/stas00/gists{/gist_id}
https://github.com/stas00
stas00
MDQ6VXNlcjEwNjc2MTAz
https://api.github.com/users/stas00/orgs
https://api.github.com/users/stas00/received_events
https://api.github.com/users/stas00/repos
https://api.github.com/users/stas00/starred{/owner}{/repo}
https://api.github.com/users/stas00/subscriptions
User
https://api.github.com/users/stas00
public
MEMBER
Yes that was the first step to add DATASETS_OFFLINE :)

With this PR, if a request times out (which couldn't happen before because no time out was set), it falls back on the local files with no error.

As you said, setting the timeout to something like 1e-16 makes the requests fail instantly, which is one step forward. One last thing left is to disable request retries and everything will be instant !
2021-02-26T18:16:45Z
https://github.com/huggingface/datasets/pull/1952#issuecomment-786811852
https://api.github.com/repos/huggingface/datasets/issues/1952
MDEyOklzc3VlQ29tbWVudDc4NjgxMTg1Mg==
https://api.github.com/repos/huggingface/datasets/issues/comments/786811852/reactions
2021-02-26T18:16:45Z
https://api.github.com/repos/huggingface/datasets/issues/comments/786811852
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
CONTRIBUTOR
Ah, fantastic. Thank you for elucidating that this PR is part of a bigger master plan!  
2021-02-26T18:22:29Z
https://github.com/huggingface/datasets/pull/1952#issuecomment-786814940
https://api.github.com/repos/huggingface/datasets/issues/1952
MDEyOklzc3VlQ29tbWVudDc4NjgxNDk0MA==
https://api.github.com/repos/huggingface/datasets/issues/comments/786814940/reactions
2021-02-26T18:22:29Z
https://api.github.com/repos/huggingface/datasets/issues/comments/786814940
https://avatars.githubusercontent.com/u/10676103?v=4
https://api.github.com/users/stas00/events{/privacy}
https://api.github.com/users/stas00/followers
https://api.github.com/users/stas00/following{/other_user}
https://api.github.com/users/stas00/gists{/gist_id}
https://github.com/stas00
stas00
MDQ6VXNlcjEwNjc2MTAz
https://api.github.com/users/stas00/orgs
https://api.github.com/users/stas00/received_events
https://api.github.com/users/stas00/repos
https://api.github.com/users/stas00/starred{/owner}{/repo}
https://api.github.com/users/stas00/subscriptions
User
https://api.github.com/users/stas00
public
MEMBER
Merging this one, then I'll open a new PR for the `DATASETS_OFFLINE` env var :)
2021-03-01T14:29:21Z
https://github.com/huggingface/datasets/pull/1952#issuecomment-787991054
https://api.github.com/repos/huggingface/datasets/issues/1952
MDEyOklzc3VlQ29tbWVudDc4Nzk5MTA1NA==
https://api.github.com/repos/huggingface/datasets/issues/comments/787991054/reactions
2021-03-01T14:29:21Z
https://api.github.com/repos/huggingface/datasets/issues/comments/787991054
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
As noticed in https://github.com/huggingface/datasets/issues/1939, timeouts were not properly handled when loading a dataset.
This caused the connection to hang indefinitely when working in a firewalled environment cc @stas00 

I added a default timeout, and included an option to our offline environment for tests to be able to simulate both connection errors and timeout errors (previously it was simulating connection errors only).

Now networks calls don't hang indefinitely.
The default timeout is set to 10sec (we might reduce it).