[New-bugs-announce] [issue37317] asyncio gather doesn't handle custom exceptions that inherit from BaseException

Carlos Mermingas report at bugs.python.org
Mon Jun 17 10:10:41 EDT 2019


New submission from Carlos Mermingas <cmermingas at gmail.com>:

asyncio.gather doesn't handle custom exception exceptions that inherit from BaseException in the same manner that it handles those that inherit from Exception, regardless of whether return_exceptions is set to True or False.

In the example below, I am using return_exceptions=True. If the custom exception inherits from Exception, a list printed, as expected. Conversely, if the custom exception inherits from BaseException, it is propagated:


import asyncio


class CustomException(BaseException):  # It works if base class changed to Exception
    pass


async def do_this(x):
    if x == 5:
        raise CustomException()
    await asyncio.sleep(1)
    print(f'THIS DONE: {x}')


async def main():
    print('BEGIN')
    tasks = [do_this(x) for x in range(1, 11)]
    result = await asyncio.gather(*tasks, return_exceptions=True)
    print(f'Result: {result}')
    print('END')


asyncio.run(main())

----------
components: Library (Lib)
messages: 345861
nosy: cmermingas
priority: normal
severity: normal
status: open
title: asyncio gather doesn't handle custom exceptions that inherit from BaseException
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37317>
_______________________________________


More information about the New-bugs-announce mailing list