Skip to content

Instantly share code, notes, and snippets.

@swinton
Created October 8, 2013 15:49
Show Gist options
  • Select an option

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

Select an option

Save swinton/6886842 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Example of gevent.with_timeout. Half the go_get calls will timeout.
"""
from gevent import monkey
monkey.patch_all()
import gevent
import requests
def go_get(delay):
resp = gevent.with_timeout(5.0, requests.get, "http://httpbin.org/delay/%d" % delay)
return resp.content
if __name__ == "__main__":
jobs = [gevent.spawn(go_get, delay) for delay in range(0, 10)]
gevent.joinall(jobs)
for job in jobs:
print job.value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment