Created
December 3, 2009 17:20
-
-
Save saivenkat/248347 to your computer and use it in GitHub Desktop.
Eventlet CouchDb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import StringIO | |
| from eventlet import coros | |
| from eventlet.green import urllib2 | |
| class EventCouchDb(): | |
| def __init__(self, url): | |
| self.url = url | |
| def fetch(self, url, callback): | |
| callback.write(urllib2.urlopen(url).read()) | |
| def get(self, callback): | |
| pool = coros.CoroutinePool(max_size=4) | |
| waiter = pool.execute(self.fetch, self.url, callback) | |
| waiter.wait() | |
| if __name__== '__main__': | |
| resource_url = "http://localhost:5984/unicef-region-data/b0a47e5de8a619ca15f12bb5908d899e" | |
| curl = EventCouchDb(resource_url) | |
| callback = StringIO.StringIO() | |
| curl.get(callback) | |
| print callback.getvalue() | |
| callback.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment