Created
October 8, 2013 15:49
-
-
Save swinton/6886842 to your computer and use it in GitHub Desktop.
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 | |
| """ | |
| 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