diff options
author | Andrew Hoos <andrewjhoos@gmail.com> | 2016-11-29 17:52:50 -0800 |
---|---|---|
committer | Andrew Hoos <andrewjhoos@gmail.com> | 2016-11-29 17:52:50 -0800 |
commit | b5acf8c95b4c1060a9bc646dcb9cf52137c8df92 (patch) | |
tree | 36ae169d227a03d4bf305fa5b4fb21ed34f530dd | |
parent | 9379e9870e64e49cdbaf80df6b2d9c5e932048bd (diff) | |
download | python-coveragepy-git-b5acf8c95b4c1060a9bc646dcb9cf52137c8df92.tar.gz |
Update code to better handle calling sys.excepthook when it throws
-rw-r--r-- | coverage/cmdline.py | 5 | ||||
-rw-r--r-- | coverage/execfile.py | 9 |
2 files changed, 9 insertions, 5 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index 89420241..bbddf0a2 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -754,10 +754,7 @@ def main(argv=None): try: status = CoverageScript().command_line(argv) except ExceptionDuringRun as err: - # An exception was caught while running the product code. The - # sys.exc_info() return tuple is packed into an ExceptionDuringRun - # exception. - traceback.print_exception(*err.args) + # An exception was caught while running the product code. status = ERR except CoverageException as err: # A controlled error inside coverage.py: print the message to the user. diff --git a/coverage/execfile.py b/coverage/execfile.py index 8ff38776..d1aa2529 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -6,6 +6,7 @@ import marshal import os import sys +import traceback import types from coverage.backward import BUILTINS @@ -195,7 +196,13 @@ def run_python_file(filename, args, package=None, modulename=None, path0=None): # call a custom user excepthook if it is provided if sys.excepthook is not sys.__excepthook__: - sys.excepthook(typ, err, tb.tb_next) + try: + sys.excepthook(typ, err, tb.tb_next) + except SystemExit: + raise + except: + typ, err, tb = sys.exc_info() + traceback.print_exception(typ, err, tb.tb_next) raise ExceptionDuringRun(typ, err, tb.tb_next) finally: |