On Tue, Nov 14, 2017 at 9:54 AM, Mark E. Haase <mehaase@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: import asyncio, traceback excluded = [ asyncio.__file__[-len(os.path.basename(asyncio.__file__)):], # preserve existing separator to attempt being platform-agnostic traceback.__file__, ] ... for frame in traceback.extract_tb(tb): if not any(frame.filename.startswith(x) for x in excluded) and frame.name.startswith("_"): Functions starting with "_" in any module can now be excluded from tracebacks. I'm not fond of this implementation, but I hope it serves to illustrate.