R. David Murray added the comment:
In the first case, once the loop has run the task it no longer has a reference
to it, and it gets GCed. The __del__ method of the task calls your exception
handler. In the second case, you have a reference to it, so __del__ does not
get called.
If you
New submission from Billy Foster:
I found a very strange bug in asyncio where whether exception handlers are
called depends on whether a task is stored.
To illustrate, the following code works as expected, printing out that it made
it to the exception handler:
import asyncio
async def run():