Skip to content
Snippets Groups Projects
Commit 30812b87 authored by Guy Jacob's avatar Guy Jacob
Browse files

Fix un-handled exception traces showing twice in stdout

parent 22e3ea8b
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,7 @@ import os
import sys
import random
import traceback
import logging
from collections import OrderedDict, defaultdict
from functools import partial
import numpy as np
......@@ -790,7 +791,14 @@ if __name__ == '__main__':
print("\n-- KeyboardInterrupt --")
except Exception as e:
if msglogger is not None:
# We catch unhandled exceptions here in order to log them to the log file
# However, using the msglogger as-is to do that means we get the trace twice in stdout - once from the
# logging operation and once from re-raising the exception. So we remove the stdout logging handler
# before logging the exception
handlers_bak = msglogger.handlers
msglogger.handlers = [h for h in msglogger.handlers if type(h) != logging.StreamHandler]
msglogger.error(traceback.format_exc())
msglogger.handlers = handlers_bak
raise
finally:
if msglogger is not None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment