Skip to content

Instantly share code, notes, and snippets.

@swinton
Created August 16, 2012 22:21
Show Gist options
  • Select an option

  • Save swinton/3374142 to your computer and use it in GitHub Desktop.

Select an option

Save swinton/3374142 to your computer and use it in GitHub Desktop.
Gevent examples
#!/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