Skip to content

Instantly share code, notes, and snippets.



Last active Jun 20, 2017
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
log.write(warnings.formatwarning(message, category, filename, lineno, line))
warnings.showwarning = warn_with_traceback

This comment has been minimized.

Copy link
Owner Author

@nvictus nvictus commented Jun 20, 2017

Thanks to user mgab at

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.