[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

Marco Pagliaricci report at bugs.python.org
Sat Oct 9 03:38:23 EDT 2021


Marco Pagliaricci <pagliaricci.m at gmail.com> added the comment:

OK, I see your point.
But I still can't understand one thing and I think it's very confusing:

1) if you see my example, inside the job() coroutine, I get correctly
cancelled with an `asyncio.CancelledError` exception containing my message.
2) Now: if I re-raise the asyncio.CancelledError as-is, I lose the message,
if I call the `asyncio.Task.exception()` function.
3) If I raise a *new* asyncio.CancelledError with a new message, inside the
job() coroutine's `except asyncio.CancelledError:` block, I still lose the
message if I call `asyncio.Task.exception()`.
4) But if I raise another exception, say `raise ValueError("TEST")`, always
from the `except asyncio.CancelledError:` block of the job() coroutine, I
*get* the message!
I get `ValueError("TEST")` by calling `asyncio.Task.exception()`, while I
don't with the `asyncio.CancelledError()` one.

Is this really wanted? Sorry, but I still find this a lot confusing.
Shouldn't it be better to return from the `asyncio.Task.exception()` the
old one (containing the message) ?
Or, otherwise, create a new instance of the exception for *ALL* the
exception classes?

Thank you for your time,
My Best Regards,

M.

On Thu, Oct 7, 2021 at 10:25 AM Thomas Grainger <report at bugs.python.org>
wrote:

>
> Thomas Grainger <tagrain at gmail.com> added the comment:
>
> afaik this is intentional https://bugs.python.org/issue31033
>
> ----------
> nosy: +graingert
>
> _______________________________________
> Python tracker <report at bugs.python.org>
> <https://bugs.python.org/issue45390>
> _______________________________________
>

----------

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


More information about the Python-bugs-list mailing list