tenacity icon indicating copy to clipboard operation
tenacity copied to clipboard

Retry for Asynchronous Generator (PEP 525)

Open heri16 opened this issue 8 years ago • 3 comments

Could we support retry for Asynchronous Generator?

import asyncio
import random
from tenacity import retry

@retry
async def ticker(delay, to):
    """Yield numbers from 0 to `to` every `delay` seconds."""
    for i in range(to):
        if random.randint(0, 10) > 1:
            raise IOError("Broken sauce, everything is hosed!!!111one")
        else:
            yield i
        await asyncio.sleep(delay)

async for i in ticker(1, 10):
    print(i)

See: PEP 525

heri16 avatar Apr 23 '17 15:04 heri16

the example looks simply impossible to do sane in the backend

RonnyPfannschmidt avatar Apr 23 '17 18:04 RonnyPfannschmidt

Hi! Why is this impossible? It would be great to have this support

ashleystendel avatar Apr 02 '24 14:04 ashleystendel

Any retrying wrapper would lose the inner State of the generator,which would have to restart

In catastrophic scenarios this could mean yielding thousand's of elements instead of 10

RonnyPfannschmidt avatar Apr 02 '24 15:04 RonnyPfannschmidt