[New-bugs-announce] [issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

Marco Pagliaricci report at bugs.python.org
Wed Oct 6 07:30:42 EDT 2021


New submission from Marco Pagliaricci <pagliaricci.m at gmail.com>:

I've spotted a little bug in how asyncio.CancelledError() exception is propagated inside an asyncio.Task.

Since python 3.9 the asyncio.Task.cancel() method has a new 'msg' parameter, that will create an asyncio.CancelledError(msg) exception incorporating that message.

The exception is successfully propagated to the coroutine the asyncio.Task is running, so the coroutine successfully gets raised an asyncio.CancelledError(msg) with the specified message in asyncio.Task.cancel(msg) method.

But, once the asyncio.Task is cancelled, is impossible to retrieve that original asyncio.CancelledError(msg) exception with the message, because it seems that *a new* asyncio.CancelledError() [without the message] is raised when asyncio.Task.result() or asyncio.Task.exception() methods are called.

I have the feeling that this is just wrong, and that the original message specified in asyncio.Task.cancel(msg) should be propagated even also asyncio.Task.result() is called.

I'm including a little snippet of code that clearly shows this bug.

I'm using python 3.9.6, in particular:
Python 3.9.6 (default, Aug 21 2021, 09:02:49) 
[GCC 10.2.1 20210110] on linux

----------
components: asyncio
files: task_bug.py
messages: 403294
nosy: asvetlov, pagliaricci.m, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.Task doesn't propagate CancelledError() exception correctly.
type: behavior
versions: Python 3.9
Added file: https://bugs.python.org/file50328/task_bug.py

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


More information about the New-bugs-announce mailing list