Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created September 25, 2012 02:56
Show Gist options
  • Save jordanorelli/3779721 to your computer and use it in GitHub Desktop.
Save jordanorelli/3779721 to your computer and use it in GitHub Desktop.
from random import randint
import gevent
def mightfail():
x = randint(1, 10)
if x == 10:
raise ValueError("that's too big")
return x
jobs = [gevent.spawn(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