[New-bugs-announce] [issue42636] shielded task exception never retrieved when outer task cancelled

Martin Natano report at bugs.python.org
Mon Dec 14 05:36:21 EST 2020

New submission from Martin Natano <natano+pythonbugs at natano.net>:

A task created with asyncio.shield() never retrieves the task exception, which results in a log message being generated. See the attached script for a minimal example. Output looks something like this:

Task exception was never retrieved
future: <Task finished name='Task-2' coro=<some_coroutine() done, defined at /Users/natano/python-bug/trigger-warning.py:4> exception=Exception('foo')>
Traceback (most recent call last):
  File "/Users/natano/python-bug/trigger-warning.py", line 6, in some_coroutine
    raise Exception('foo')
Exception: foo

I believe this behaviour is not intended and is an unintended side-effect of commit b35acc5b3a0148c5fd4462968b310fb436726d5a (https://github.com/python/cpython/commit/b35acc5b3a0148c5fd4462968b310fb436726d5a). The _inner_done_callback has has code to retrieve the exception when the outer task was cancelled, but since that commit the _inner_done_callback is not called anymore when the outer task was cancelled.

(Tested with 3.8, 3.9 and 3.10. I don't have a python 3.7 version available for testing, but I think this issue also affects 3.7.)

components: asyncio
files: trigger-warning.py
messages: 382975
nosy: asvetlov, natano, yselivanov
priority: normal
severity: normal
status: open
title: shielded task exception never retrieved when outer task cancelled
versions: Python 3.10, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file49679/trigger-warning.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list