Created
September 25, 2012 03:00
-
-
Save jordanorelli/3779736 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
from random import randint | |
from gevent.util import wrap_errors | |
import gevent | |
def mightfail(): | |
x = randint(1, 10) | |
if x == 10: | |
raise ValueError("that's too big") | |
return x | |
jobs = [gevent.spawn(wrap_errors(Exception, mightfail)) for x in xrange(50)] | |
gevent.joinall(jobs, timeout=2) | |
jobs_that_succeeded = filter(lambda job: job.successful(), jobs) | |
jobs_that_failed = filter(lambda job: not job.successful(), jobs) | |
print [job.value for job in jobs_that_succeeded] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment