On Tue, Nov 14, 2017 at 2:00 PM, Roger Pate <rogerp...@gmail.com> wrote:
> On Tue, Nov 14, 2017 at 9:54 AM, Mark E. Haase <meha...@gmail.com> wrote:
> ...
>>         print('Async Traceback (most recent call last):')
>>         for frame in traceback.extract_tb(tb):
>>             head, tail = os.path.split(frame.filename)
>>             if (head.endswith('asyncio') or tail == 'traceback.py') and \
>>                 frame.name.startswith('_'):
> ...
>> The meat of it is towards the bottom, "if head.endswith('asyncio')..."There
>> are a lot of debatable details and this implementation is pretty hacky and
>> clumsy, but I have found it valuable in my own usage, and I haven't yet
>> missed the omitted stack frames.
>
> It would be better to determine if the qualified module name is
> "traceback" or starts with "asyncio." (or topmost package is
> "asyncio", etc.) rather than allow false positives for
> random_package.asyncio.module._any_function or
> random_package.traceback._any_function.  I don't see an easy way to
> get the module object at this point in your hook; however:

You can't get the module from the cooked data that extract_tb returns,
but it's there in the tb object itself. This walks the traceback and
prints each frame's module:

current = tb
while current is not None:
    print("Next module", current.tb_frame.f_globals.get("__name__"))
    current = current.tb_next

-n

-- 
Nathaniel J. Smith -- https://vorpus.org
_______________________________________________
Async-sig mailing list
Async-sig@python.org
https://mail.python.org/mailman/listinfo/async-sig
Code of Conduct: https://www.python.org/psf/codeofconduct/

Reply via email to