Last active
June 20, 2017 21:24
-
-
Save nvictus/a1de6faf25e76efd3c33cc76ae7180fa to your computer and use it in GitHub Desktop.
print traceback in warnings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to user mgab at https://stackoverflow.com/a/22376126