ZeevG / python-forecast.io

A thin Python Wrapper for the Dark Sky (formerly forecast.io) weather API
http://zeevgilovitz.com/python-forecast.io/
Other
423 stars 88 forks source link

Add timeout to prevent API calls from never returning #41

Open balloob opened 8 years ago

balloob commented 8 years ago

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

ZeevG commented 8 years ago

@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.

fabaff commented 8 years ago

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.

balloob commented 7 years ago

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.