python-forecast.io icon indicating copy to clipboard operation
python-forecast.io copied to clipboard

Add timeout to prevent API calls from never returning

Open balloob opened this issue 10 years ago • 3 comments

This PR adds a 10 second timeout to prevent requests from staying open forever.

balloob avatar Dec 12 '15 23:12 balloob

@balloob @fabaff Are you able to tell me a bit more about why you need this timeout? I'm a bit hesitant to add a fixed timeout in case it is unsuitable for some applications. I could make it an option but I don't want to pollute the API with unnecessary, rarely used options.

Most http proxies will close the connection if the application server doesn't respond within a certain time limit, usually around 30 - 60 seconds. I don't know for certain but I'd expect the Dark Sky API would do this.

ZeevG avatar Oct 03 '16 10:10 ZeevG

requests doesn't have a default timeout like browsers do and most providers appreciate if the client is taking care about the connections they initiated. Sure, chances are high that servers will terminate the connection at some point to free-up resources.

The requests are not pooled or re-used, as in a session, so it doesn't make much sense to keep them long-running.

fabaff avatar Oct 03 '16 14:10 fabaff

I don't know for certain but I'd expect the Dark Sky API would do this

It's not a good idea to rely on the other party to prevent your program from getting blocked. I don't mind setting it to 60 seconds if that is fine. In the end, you want some sort of timeout or else the program might never unblock.

balloob avatar Apr 05 '17 14:04 balloob