Commit 63b3e8a9 authored by Denis Bilenko's avatar Denis Bilenko

simplify joinall and remove _joinall

parent 5da85b40
......@@ -127,7 +127,7 @@ def killall(greenlets, exception=GreenletExit, block=False, polling_period=0.2):
if block:
alive = waiter.wait()
if alive:
_joinall(alive, polling_period=polling_period)
joinall(alive, polling_period=polling_period)
def join(greenlet, polling_period=0.2):
......@@ -138,24 +138,17 @@ def join(greenlet, polling_period=0.2):
sleep(delay)
def _joinall(greenlets, polling_period=0.2):
"""Wait for the greenlets to finish by polling their status.
WARNING: greenlets argument is corrupted.
"""
while greenlets and greenlets[0].dead:
del greenlets[0]
def joinall(greenlets, polling_period=0.2):
"""Wait for the greenlets to finish by polling their status"""
current = 0
while current < len(greenlets) and greenlets[current].dead:
current += 1
delay = 0.002
while greenlets:
while current < len(greenlets):
delay = min(polling_period, delay*2)
sleep(delay)
while greenlets and greenlets[-1].dead:
del greenlets[-1]
def joinall(greenlets, polling_period=0.2):
"""Wait for the greenlets to finish by polling their status"""
return _joinall(list(greenlets), polling_period=polling_period)
while current < len(greenlets) and greenlets[current].dead:
current += 1
try:
......
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