New submission from Andrew Lytvyn:

If you do not await gather, then if one of gather inner coroutines fails, 
others keep working, but they should not.


```python
import asyncio
import logging

logging.basicConfig(level=logging.DEBUG)

loop = asyncio.get_event_loop()

async def success_coro(seconds):
    await asyncio.sleep(seconds)
    print(seconds)


async def failed_coro(seconds):
    await asyncio.sleep(seconds)
    print(seconds)
    raise ZeroDivisionError

coros = [
    success_coro(2),
    failed_coro(3),
    success_coro(5),
]

async def waiter():
    await asyncio.gather(*coros)

asyncio.ensure_future(waiter())

loop.run_forever()
```
-------------------------------------------------------------
Console:
2
3
ERROR:asyncio:Task exception was never retrieved
future: <Task finished coro=<waiter() done, defined at tst.py:72> 
exception=ZeroDivisionError()>
Traceback (most recent call last):
  File "tst.py", line 73, in waiter
    await asyncio.gather(*coros)
  File "tst.py", line 64, in failed_coro
    raise ZeroDivisionError
ZeroDivisionError
5
-------------------------------------------------------------

Expected behavior that 5 should not be printed.

----------
components: asyncio
messages: 302079
nosy: Andrew Lytvyn, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.gather does not cancel tasks if one fails
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31452>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to