Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created September 25, 2012 03:00
Show Gist options
  • Save jordanorelli/3779736 to your computer and use it in GitHub Desktop.
Save jordanorelli/3779736 to your computer and use it in GitHub Desktop.
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