I'm new to the asyncio framework and I'm using trollius on python 2.7.

The question I have is what's the general best practice of looking at stack 
trace.  From what I'm trying to do simply:

import asyncio
from asyncio import From, Return
import traceback


@asyncio.coroutine
def bar():
    raise TypeError('Blah')


@asyncio.coroutine
def foo():
    raise Return((yield From(bar())))


@asyncio.coroutine
def wrap():
    try:
        yield From(foo())
    except Exception:
        traceback.print_exc()
        raise

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(foo())
    loop.close()

First of all, the top level stack trace would only reflect what's in the 
event loop, so it's not useful at all.

If I change the run_until_complete(foo()) to run_until_complete(wrap()), 
again the traceback is not useful since it only reports on the 'yield 
From(foo())' line.  I see that you can wrap the coroutine into a task and 
do a yield on it, and the task has a print_stack() function, but I can't 
get it to work as well.

I'm out of idea on how to do this properly as it should be an obvious (and 
very important!) thing to do.  What's the right approach to this?

Thanks!

Will


Reply via email to