google app engine - AppEngine's urlfetch, how to force timeout to be respected -
i'm using urlfetch google appengine, , add deadline parameter force deadline short (3 seconds), following :
try: urlfetch.set_default_fetch_deadline(3) return urlfetch.fetch(url='http://www.example.com', method=urlfetch.get, deadline=3) except google.appengine.runtime.apiproxy_errors.deadlineexceedederror: pass except google.appengine.api.urlfetch_errors.deadlineexceedederror: pass return none
but no matter what, thread goes on , on 60 seconds (the max execution time http request on appengine) , fail miserably on deadlineexception ("thread running after request.").
is there way ensure upper query strictly stopped in 3 seconds?
i can share code have running in 1 of production projects. use deadline of 0.5 seconds in example. last checked, it's still working:
t_rpc = urlfetch.create_rpc(deadline=0.5) urlfetch.make_fetch_call(t_rpc, url) # , later... try: result = t_rpc.get_result() except: # handle errors... pass # use result...
this using asynchronous version of api can technically things in between calling make_fetch_call
, get_result
. otherwise, can call them back-to-back , function same synchronous api.
Comments
Post a Comment