This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cmermingas
Recipients cmermingas
Date 2019-06-17.14:10:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1560780641.84.0.00364750397427.issue37317@roundup.psfhosted.org>
In-reply-to
Content
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())
History
Date User Action Args
2019-06-17 14:10:41cmermingassetrecipients: + cmermingas
2019-06-17 14:10:41cmermingassetmessageid: <1560780641.84.0.00364750397427.issue37317@roundup.psfhosted.org>
2019-06-17 14:10:41cmermingaslinkissue37317 messages
2019-06-17 14:10:41cmermingascreate