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 pagliaricci.m
Recipients asvetlov, pagliaricci.m, yselivanov
Date 2021-10-06.11:30:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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
Date User Action Args
2021-10-06 11:30:42pagliaricci.msetrecipients: + pagliaricci.m, asvetlov, yselivanov
2021-10-06 11:30:42pagliaricci.msetmessageid: <>
2021-10-06 11:30:42pagliaricci.mlinkissue45390 messages
2021-10-06 11:30:42pagliaricci.mcreate