Commit ea0d5607 authored by Denis Bilenko's avatar Denis Bilenko

add 'count' argument to joinall

parent a63ab5e1
...@@ -502,30 +502,32 @@ def _kill(greenlet, exception, waiter): ...@@ -502,30 +502,32 @@ def _kill(greenlet, exception, waiter):
waiter.switch() waiter.switch()
def joinall(greenlets, timeout=None, raise_error=False): def joinall(greenlets, timeout=None, raise_error=False, count=None):
xrange = six.moves.xrange xrange = six.moves.xrange
from gevent.queue import Queue from gevent.queue import Queue
queue = Queue() queue = Queue()
put = queue.put put = queue.put
if count is None:
count = len(greenlets)
timeout = Timeout.start_new(timeout) timeout = Timeout.start_new(timeout)
try: try:
try: try:
for greenlet in greenlets: for greenlet in greenlets:
greenlet.rawlink(put) greenlet.rawlink(put)
if raise_error: if raise_error:
for _ in xrange(len(greenlets)): for _ in xrange(count):
greenlet = queue.get() greenlet = queue.get()
if not greenlet.successful(): if not greenlet.successful():
raise greenlet.exception raise greenlet.exception
else: else:
for _ in xrange(len(greenlets)): for _ in xrange(count):
queue.get() queue.get()
except: except:
for greenlet in greenlets:
greenlet.unlink(put)
if sys.exc_info()[1] is not timeout: if sys.exc_info()[1] is not timeout:
raise raise
finally:
for greenlet in greenlets:
greenlet.unlink(put)
finally: finally:
timeout.cancel() timeout.cancel()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment