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


i have route in flask app pulls data external server , pushes results front end. external server slow or unresponsive. what's best way place timeout on route call, front end doesn't hang if external server lagging? or there more appropriate way handle situation in flask (not apache, nginx, etc)?

my goal timeout route call, not keep arbitrary long process alive question: time out issues chrome , flask. options websockets run background processes/threads until finish; however, want stop slow route call after fixed amount of time has elapsed. timeout on function call , python timeout within flask context. celery's task decorator (concurrent asynchronous processes python, flask , celery) seems great solution, don't want require large dependency use small amount of functionality.

not entirely sure if i'm right this, understanding if thread (or greenthread) handling request network call in it's own "foreground", , call times out, borken pipe pretty going happen. can spin off fully-separate thread network request, call thread.join() timeout in request-handling code.

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

at point, call thread.isalive() (still in request-handling code path) , if true, network call didn't return in time, , return error state.

if it's false - , you'll need have "worker" thread update (thread-safe) data structure response data - response data , go on way.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -