This is what I tried:
>>> import asyncio
>>> @asyncio.coroutine
... def f():
... print("RUN")
... raise Exception("ciao")
...
>>> asyncio.ensure_future(f())
<Task pending coro=<coro() running at /usr/lib/python3.4/asyncio/coroutines.py:139>>
>>> loop = asyncio.get_event_loop()
>>> loop.run_forever()
RUN
and the stack trace is not retrieved. If I run the coroutine with asyncio.run_until_complete(f())
there's no problem.
You have to wait for the result of the coroutine somewhere, and the exception will be raised in that context. All coroutines need to be "awaited";
asyncio.run_until_complete()
will do that implicitly for you, butrun_forever()
can't, since it is supposed to run, well, forever. Here's an example how you can see the exception (using Python 3.5 syntax):