pedrohm / gdata-python-client

Automatically exported from code.google.com/p/gdata-python-client
0 stars 0 forks source link

Add support for Google App Engine's Async HTTP Client #345

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Google App Engine added a few months support for asynchronous HTTP requests:
http://code.google.com/appengine/docs/python/urlfetch/asynchronousrequests.html

In the case where you are querying several resource (for instance, connecting 
to multiple 
services, like calendar and docs) right now you can't easily paralelize the 
service calls.

The attached patch (against version 2.0.8) touches only two files: 
gdata/service.py and 
gdata/alt/appengine.py.
(I'm aware that new development is being done against client.py; however, I'm 
still using the 
"old" APIs) 

Changes to gdata/service.py:

We split the Get method into two; Get contains all the code until self.request 
is called, 
GetFinished is responsible for processing the server response.
And here is the big API change: if the http client used has an "async" member 
set to true, instead 
of returning the response directly, we return a lambda to the function that 
generates the 
response.
This part of the code has nothing to do with Google App Engine and would work 
on any backend 
that defined this async flag.

Changes to gdata/alt/appengine.py:

This could have been done with a lot less code, by refactoring the existing 
classes, but I tried 
keeping the impact of this patch as small as possible for the existing use 
cases, so ended up 
duplicating the AppEngineHttpClient and HttpResponse classes into Async 
versions.

To enable this code, you pass an extra "async=true" to the run_on_appengine 
call.

The async classes themselves are quite straightforward; the response object 
instead of having 
the response stores the RPC and only fetches the response contents when read or 
getheader are 
actually called.

I don't think the patch can be commited as is, but hopefully with can improve 
it or end up with 
an alternative solution.

Original issue reported on code.google.com by morais.p...@gmail.com on 28 Feb 2010 at 6:49

Attachments:

GoogleCodeExporter commented 9 years ago
Type should be enhancement, not defect.

Original comment by morais.p...@gmail.com on 28 Feb 2010 at 6:51

GoogleCodeExporter commented 9 years ago

Original comment by jscud.w...@gmail.com on 1 Mar 2010 at 11:48