Created
August 16, 2012 22:21
-
-
Save swinton/3374142 to your computer and use it in GitHub Desktop.
Gevent examples
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
| #!/usr/bin/env python | |
| """ | |
| Gevent examples. | |
| """ | |
| import json | |
| import gevent | |
| import requests | |
| def receiver(g): | |
| print "Got value", json.loads(g.value.content) | |
| def fetch(url): | |
| return requests.get(url) | |
| def link_value_example(): | |
| """ | |
| Example showing link_value usage. | |
| """ | |
| g = gevent.spawn(fetch, "http://api.twitter.com/1/users/show.json?screen_name=steveWINton") | |
| # receiver will be called once the request is complete | |
| g.link_value(receiver) | |
| gevent.joinall([g]) | |
| if __name__ == "__main__": | |
| link_value_example() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment