3

I've got a Python app making 3 different api calls one after another in the same block of code. I'd like to execute these calls asynchronously, and then perform an action when they're all complete.

A couple notes:

  • Other answers regarding async actions point to frameworks like Twisted and Celery, but I'm building a Web2Py app for the GAE, so those daemon-based frameworks aren't an option AFAIK.
  • I'm using api wrapper libraries for the various apis, so I'm wondering if there's an async solution that can be implemented at the thread level, rather than the http request level?
Yarin
  • 173,523
  • 149
  • 402
  • 512
  • 1
    You can make async URL Fetch calls, if that's helpful: http://code.google.com/appengine/docs/python/urlfetch/asynchronousrequests.html – Amy U. Feb 29 '12 at 02:07
  • Amy- that may be the best/only answer- make it an answer so I can give you some cred.. – Yarin Feb 29 '12 at 12:11

3 Answers3

3

Python supports async URL Fetch calls, which may be helpful: http://code.google.com/appengine/docs/python/urlfetch/asynchronousrequests.html

Amy U.
  • 2,227
  • 11
  • 11
  • Assuming your async URL fetches will be against worker pages you have created, you probably need to enable Concurrent Requests to make sure they actually execute in parallel: http://code.google.com/appengine/docs/python/python27/newin27.html#Concurrent_Requests – Raven Mar 03 '12 at 18:37
1

If you're brave, you might try the Experimental new DB api, NDB. It has async APIs for working with the datastore + URL fetch. If those are the things you hoped to do async-ly, then you're in luck.

1

Task Queues might get you there. I don't see any promises about responsiveness, but you can definitely control how many tasks are started per second.

Raven
  • 1,264
  • 1
  • 12
  • 22
  • Raven- In my case I need be able to perform an action on completion- I don't see any callback or listener functionality for task queues. However, they look like they could be useful elsewhere, and I didn't know about them, so thanks. – Yarin Mar 02 '12 at 12:58
  • @Yarin You could have your tasks write the results to the datastore. Then the main code could poll for completion. – Raven Mar 03 '12 at 18:34