New submission from Marco Pagliaricci <pagliaricc...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue45390>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to