Place a timeout on calls to an unresponsive Flask route (updated) Place a timeout on calls to an unresponsive Flask route (updated) flask flask

Place a timeout on calls to an unresponsive Flask route (updated)


Not entirely sure if I'm right about all this, but my understanding is that if the thread (or greenthread) handling the request does the network call in it's own "foreground", and that call times out, the borken pipe is pretty much going to happen. But what you can do is spin off a fully-separate thread that does the network request, then call Thread.join() with a timeout in your request-handling code.

http://docs.python.org/2/library/threading.html#threading.Thread.join

At that point, call Thread.isAlive() (still in your request-handling code path) and if True, the network call didn't return in time, and you return your error state.

If it's False - and you'll need to have the "worker" thread update some (thread-safe) data structure with the response data - you get that response data and go on your way.