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.

classification
Title: asyncio: loop.run_forever() should consume exception of the temporary task
Type: Stage:
Components: asyncio Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, martin.panter, python-dev, vstinner, yselivanov
Priority: normal Keywords: patch

Created on 2014-10-10 12:07 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
run_forever.patch vstinner, 2014-10-10 12:07 review
Messages (4)
msg228994 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-10-10 12:07
BaseEventLoop.run_forever() creates a temporary task when it gets a coroutine object. If the coroutine raises a base exception, it is stored in the temporary task (task.set_exception(exc)). run_forever() doesn't catch the exception, which is the expected behaviour.

The problem is that the temporary task still holds the exception, whereas the caller doesn't have access to this temporary task object. As a result, a warning is logger.

I propose to simply drop the exception from the task object (consume it). The call will get it anyway, it's not catched.

Attached patch implements this idea with a unit test.
msg229078 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-10-11 12:23
I tried to reply to Guido on Rietveld but I got an HTTP error 500.

Guido wrote:
> LGTM.

Cool, I will commit my change to Tulip & Python.

> In the long run I think we'll need to revisit the decision to not catch
> BaseException in a few places. There are quite a few issues around these, if the
> app *does* catch them and keeps going there may be some confused states.

There is at least another issue: #22429.
msg229079 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-10-11 12:36
I pushed the commit to Tulip: changeset e610f1408243.
msg229080 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-11 12:36
New changeset fb65b9ed8023 by Victor Stinner in branch '3.4':
Issue #22601: run_forever() now consumes BaseException of the temporary task
https://hg.python.org/cpython/rev/fb65b9ed8023

New changeset 8437e2bfe7a9 by Victor Stinner in branch 'default':
(Merge 3.4) Issue #22601: run_forever() now consumes BaseException of the
https://hg.python.org/cpython/rev/8437e2bfe7a9
History
Date User Action Args
2022-04-11 14:58:08adminsetgithub: 66791
2014-10-11 12:36:59vstinnersetstatus: open -> closed
resolution: fixed
2014-10-11 12:36:40python-devsetnosy: + python-dev
messages: + msg229080
2014-10-11 12:36:08vstinnersetmessages: + msg229079
2014-10-11 12:23:41vstinnersetmessages: + msg229078
2014-10-10 13:25:34martin.pantersetnosy: + martin.panter
2014-10-10 12:07:33vstinnercreate