Chris Jerdonek <chris.jerdo...@gmail.com> added the comment:
I took a look at this. Basically, the reason the exception handler isn't firing when the task is still in scope is that the exception handler is only a handler of "last resort." You can see that the exception handler is called inside Task.__del__ here: https://github.com/python/cpython/blob/3764069f3ba2a7e932837ae19265059339dc86e3/Lib/asyncio/tasks.py#L167-L176 The reason to do it this way is that if the Task is still in scope, there's still a chance that the caller might want to handle the exception themselves, e.g. by awaiting on the Task themselves. It's only when all references to the task go away that you know that the Task's exceptions can no longer be handled manually. Maybe this would be worth clarifying somewhere in the Error Handling API docs: https://docs.python.org/3/library/asyncio-eventloop.html#error-handling-api If you agree, we can change this issue to a documentation issue. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39839> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com