Added exception handler

This commit is contained in:
Mark Qvist 2023-10-28 22:59:52 +02:00
parent 54e5256ea4
commit 93a0b5fb55
2 changed files with 19 additions and 4 deletions

View file

@ -1,5 +1,6 @@
__debug_build__ = True
__debug_build__ = False
import sys
import time
import RNS
from os import environ
@ -367,4 +368,19 @@ class SidebandService():
self.sideband.cleanup()
self.release_locks()
def handle_exception(exc_type, exc_value, exc_traceback):
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
if exc_type == SystemExit:
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
import traceback
exc_text = "".join(traceback.format_exception(exc_type, exc_value, exc_traceback))
RNS.log(f"An unhandled {str(exc_type)} exception occurred: {str(exc_value)}", RNS.LOG_ERROR)
RNS.log(exc_text, RNS.LOG_ERROR)
sys.excepthook = handle_exception
SidebandService().start()