Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upimplementation of asyncio.wait waiting for iterator is not complete #461
Comments
|
Actually, import asyncio
async def task1():
await asyncio.sleep(3)
raise RuntimeError
async def task2():
await asyncio.sleep(10)
async def main():
tasks = [task1(), task2()]
done, pending = await asyncio.wait(tasks, return_when='FIRST_COMPLETED')
exception = done.pop().exception()
assert isinstance(exception, RuntimeError)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close() |
|
@005 I'd be interested in the actual code that caused this suggestion. |
|
it looks its not asyncio, but something esle. here is the simplest example i could come up with. notice there are 2 urls that server will handle /1 open each one in different browser tab, and then there will be a difference
|


asyncio.wait has 3 different options to run with
Constant Description
FIRST_COMPLETED The function will return when any future finishes or is cancelled.
FIRST_EXCEPTION The function will return when any future finishes by raising an exception. If no future raises an exception then it is equivalent to ALL_COMPLETED.
ALL_COMPLETED The function will return when all futures finish or are cancelled.
but there is no way to run it in 4-th mode FIRST_COMPLETED + FIRST_EXCEPTION
which is "must-have" in the case when it suppose to wait for iterator
it will send totally legit Exception about end of iteration
but asyncio.wait has no way to catch/handle it properly.