google-app-engine


AppEngine's urlfetch, how to force timeout to be respected


I'm using Urlfetch from Google Appengine, and I add the deadline parameter to force the deadline to be short (3 seconds), like the 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, my thread goes on and on for 60 seconds (the max execution time for an http request on Appengine) and then fail miserably on a DeadlineException ("Thread running after request.").
Is there a way to ensure that the upper query will be strictly stopped in 3 seconds?
I can share some code I currently have running in one of my production projects. I use a deadline of 0.5 seconds in this example. Last I checked, it's still working:
t_rpc = urlfetch.create_rpc(deadline=0.5)
urlfetch.make_fetch_call(t_rpc, url)
# and then later...
try:
result = t_rpc.get_result()
except:
# handle errors...
pass
# use the result...
This is actually using the asynchronous version of the API so you can technically do things in between calling make_fetch_call and get_result. Otherwise, you can just call them back-to-back and it will function the same as a synchronous API.

Related Links

GAE 1.7.3 - How to debug appengine-web.xml XML error validating
How to setup data fixtures in Google App Engine for Go
How to write a JDO Query to sort result based on long attribute?
GAE doesn't import gflags
Real time notification system on Google App Engine(GAE)
How can I easily get a list of the indexed terms from a search index in the google appengine full text search api in java?
jpa #version on google appengine with #OneToMany: appengine bug or usage error?
How can I delete old backup via cron?
Error on itext-gae.jar
How to get the original from address in a forwarded message in google app engine?
Cannot authorize my google app to access my Cloud SQL instance
GooglePlaces autocomplete - more than one input
Import GAE data through Storage into BigQuery fails
Google AppEngine Tutorial, difference between code snippets
OpenID sign in not working in Gmail contextual gadget
Problems getting a basic JAXRS + JPA version working on GAE

Categories

HOME
cygwin
jmeter
css3
redux-form
rdbms
angular-formly
mstest
r-googlesheets
appcelerator
switch-statement
scripting
nstableheaderview
lanczos
character
emoji
stellar.js
favicon
code-generation
package-managers
esoteric-languages
package.json
dimensional-modeling
red5
android-7.0-nougat
gmm
oledb
visual-glitch
guzzle
ios10.2
parcelable
imageresizer
strongname
apktool
vex
panoramas
recurring-events
database-comparison
erb
mailkit
code-snippets
biztalk-rule-engine
hunspell
baidu-map
getlasterror
android-augmented-reality
sim-card
loading
signals-slots
kill
preloader
geotiff
activeperl
excel-dna
er-diagram
quicktime
monkey
cpu-cache
pybrain
javafx-css
sandcastle
gets
pytables
greatest-n-per-group
jboss-tools
shopping
nio2
design-principles
atan2
tfs-workitem
iokit
sapscript
sql-server-data-tools
dnssec
snackbar
webmatrix-3
codeplex
websphere-esb
cfcache
xmltodict
ecslidingviewcontroller
hibernate-entitymanager
kogrid
ui-select2
joomla-template
onload-event
cardreader
android-loadermanager
monotouch.dialog
vfs
zope.interface
saleslogix
usertype
expression-blend-4
tournament
umra
dataform
photolibrary
silent
globals
drupal-fivestar
hbm2java
sifr
qtabbar
web-application-project
information-management

Resources

Encrypt Message