I’m reading the documentation for asynchronous fetch requests in GAE. Python isn’t my first language, so I’m having trouble finding out what would be best for my case. I don’t really need or care about the response for the request, I just need it to send the request and forget about it and move on to other tasks.
So I tried code like in the documentation:
from google.appengine.api import urlfetch
rpc = urlfetch.create_rpc()
urlfetch.make_fetch_call(rpc, "http://www.google.com/")
# ... do other things ...
try:
result = rpc.get_result()
if result.status_code == 200:
text = result.content
# ...
except urlfetch.DownloadError:
# Request timed out or failed.
# ...
But this code doesn’t work unless I include try: and except, which I really don’t care for. Omitting that part makes the request not go through though.
What is the best option for creating fetch requests where I don’t care for the response, so that it just begins the request, and moves on to whatever other tasks there are, and never looks back?
Just do your tasks where the
comment is. When you are otherwise finished, then call
rpc.wait(). Note that it’s not thetry/exceptthat’s making it work, it’s theget_result()call. That can be replaced withwait().So your code would look like this: