From edee5e6b58c11da96d86bcb46012482e609f3112 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Fri, 21 Oct 2016 23:11:18 +0200 Subject: [PATCH] Log the exception if the worker fails. --- tools.py | 10 ++++++++++ vigil | 9 --------- worker.py | 15 +++++++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tools.py b/tools.py index dd2bb21..aa014da 100644 --- a/tools.py +++ b/tools.py @@ -563,6 +563,16 @@ php5_syntax.dependencies = {"php"} ############################# + +LOG_PATH = os.path.join(os.getcwd(), "vigil.log") + + +def log_error(message=None): + message = traceback.format_exc() if message is None else message + "\n" + with open(LOG_PATH, "a") as log_file: + log_file.write(message) + + def lru_cache_with_eviction(maxsize=128, typed=False): versions = {} make_key = functools._make_key diff --git a/vigil b/vigil index 0e65762..1b07dd2 100755 --- a/vigil +++ b/vigil @@ -84,15 +84,6 @@ KEYS_DOC = """Keys: """ -LOG_PATH = os.path.join(os.getcwd(), "vigil.log") - - -def log_error(message=None): - message = traceback.format_exc() if message is None else message + "\n" - with open(LOG_PATH, "a") as log_file: - log_file.write(message) - - class Entry(collections.UserList): def __init__(self, path, results, summary, highlighted=None, diff --git a/worker.py b/worker.py index 6da91bc..067b5b9 100755 --- a/worker.py +++ b/worker.py @@ -81,12 +81,15 @@ class Worker: def main(): print(os.getpid(), flush=True) - while True: - tool_name, path = input(), input() - tool = getattr(tools, tool_name) - result = tools.Result(path, tool) - status, result.result = tools.run_tool_no_error(path, tool) - print(status.value, flush=True) + try: + while True: + tool_name, path = input(), input() + tool = getattr(tools, tool_name) + result = tools.Result(path, tool) + status, result.result = tools.run_tool_no_error(path, tool) + print(status.value, flush=True) + except: + tools.log_error() if __name__ == "__main__":