Created
March 25, 2020 19:37
-
-
Save toby-p/486a7377af6485925cb3edd2cc007190 to your computer and use it in GitHub Desktop.
Show Python warnings with full traceback (from: https://stackoverflow.com/questions/22373927/get-traceback-of-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