You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
shielded task exception never retrieved when outer task cancelled #86802
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:
<snip>
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_coroutineraiseException('foo')
Exception: foo
</snip>
I believe this behaviour is not intended and is an unintended side-effect of commit b35acc5 (b35acc5). 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.)
I didn't test but looks like outer.exception() call can suppress the message about not retrieved exception.
natano commented on Dec 15, 2020
natanomannequin
MannequinAuthor
More actions
How would calling outer.exception() suppress the message? This happens when the outer task is cancelled while the inner task is still running. In that case the exception is never set on outer.
Activity
natano commentedon Dec 14, 2020
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:
I believe this behaviour is not intended and is an unintended side-effect of commit b35acc5 (b35acc5). 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.)
natano commentedon Dec 14, 2020
I'm not sure how to fix this, but here is a regression test for the issue. (failing on the current master branch)
asvetlov commentedon Dec 14, 2020
Thanks for the report.
I didn't test but looks like
outer.exception()call can suppress the message about not retrieved exception.natano commentedon Dec 15, 2020
How would calling
outer.exception()suppress the message? This happens when the outer task is cancelled while the inner task is still running. In that case the exception is never set on outer.5 remaining items
pythongh-86802: Fix asyncio memory leak; shielded tasks where cancell…
gh-86802: Fix asyncio memory leak; shielded task exceptions log once …
pythongh-86802: Fix asyncio memory leak; shielded task exceptions log…
[3.14] gh-86802: Fix asyncio memory leak; shielded task exceptions lo…
Revert "pythongh-86802: Fix asyncio memory leak; shielded task except…
Merge branch 'pythongh-86802' into pythongh-90871
Revert "pythongh-86802: Fix asyncio memory leak; shielded task except…
pythongh-86802: Fix asyncio memory leak; shielded task exceptions log…
pythongh-86802: Fix asyncio memory leak; shielded task exceptions log…
pythongh-86802: Fix asyncio memory leak; shielded task exceptions log…