dbrattli / aioreactive

Async/await reactive tools for Python 3.11+
MIT License
350 stars 24 forks source link

from_iterable does not handle exceptions in iterables #10

Open dmzkrsk opened 7 years ago

dmzkrsk commented 7 years ago
import asyncio
from aioreactive.core import AsyncObservable, run

async def generator():
    # Also fails with sync generators
    for i in range(10):
        if i > 2:
            print("Let's raise")
            raise ValueError(i)
            # stream hangs here

        await asyncio.sleep(.1)
        print('Yield', i)
        yield i

async def main():
    iterable = generator()
    observer = AsyncObservable.from_iterable(iterable)
    await run(observer, timeout=None)

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
    loop.close()

So the flow is simply hangs after the exception is thrown in the generator