Skip to content

Commit

Permalink
add a generic thread exception handler to remotehosts.py
Browse files Browse the repository at this point in the history
  • Loading branch information
k-rister committed May 4, 2024
1 parent 2ea9852 commit efdd6e7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions endpoints/remotehosts/remotehosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import tempfile
import threading
import time
import traceback

TOOLBOX_HOME = os.environ.get('TOOLBOX_HOME')
if TOOLBOX_HOME is None:
Expand Down Expand Up @@ -3721,6 +3722,28 @@ def setup_logger():

return logging.getLogger(__file__)

def thread_exception_hook(args):
"""
Generic thread exception handler
Args:
args (namespace): information about the exception being handled
Globals:
log: a logger instance
Returns:
None
"""
thread_name = "UNKNOWN"
if not args.thread is None:
thread_name = args.thread.name

msg = "[Thread %s] Thread failed with exception:\ntype: %s\nvalue: %s\ntraceback:\n%s" % (thread_name, args.exc_type, args.exc_value, "".join(traceback.format_list(traceback.extract_tb(args.exc_traceback))))
log.error(msg, stacklevel = 3)

return

def main():
"""
Main control block
Expand All @@ -3738,6 +3761,8 @@ def main():
global log
global settings

threading.excepthook = thread_exception_hook

if args.validate:
return(validate())

Expand Down

0 comments on commit efdd6e7

Please sign in to comment.