Skip to content

Instantly share code, notes, and snippets.

@nvictus

nvictus/tbwarn.py

Last active Jun 20, 2017
Embed
What would you like to do?
print traceback in warnings
import traceback
import warnings
import sys
def warn_with_traceback(message, category, filename, lineno, file=None, line=None):
log = file if hasattr(file,'write') else sys.stderr
traceback.print_stack(file=log)
log.write(warnings.formatwarning(message, category, filename, lineno, line))
warnings.showwarning = warn_with_traceback
@nvictus

This comment has been minimized.

Copy link
Owner Author

@nvictus nvictus commented Jun 20, 2017

Thanks to user mgab at https://stackoverflow.com/a/22376126

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.