New submission from Carlos Mermingas <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue37317>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com