From fb65c1effce3c925096e0e838d48704e43a0c7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Thu, 7 Mar 2024 08:08:01 +0100 Subject: [PATCH] Add exception_handler --- src/sidecar.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/sidecar.py b/src/sidecar.py index a48b0a16..515fec11 100644 --- a/src/sidecar.py +++ b/src/sidecar.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -import os -import re +import os, sys, re from kubernetes import client, config from kubernetes.client import ApiException @@ -33,6 +32,17 @@ logger = get_logger() +def exception_handler(exc_type, exc_value, exc_traceback): + if issubclass(exc_type, KeyboardInterrupt): + sys.__excepthook__(exc_type, exc_value, exc_traceback) + return + + logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback)) + + +sys.excepthook = exception_handler + + def main(): logger.info("Starting collector")