exception handler and bug fixes

This commit is contained in:
Sander Land committed 2020-06-04 23:26:44 +02:00
1 parent 372a98ae1f
commit 20f4598410
6 files changed
+100 -23

No files matched your search

+22 -2
View File
@@ -1,5 +1,8 @@
# first, logging level lower
import os
from kivy.base import ExceptionHandler, ExceptionManager
os.environ["KCFG_KIVY_LOG_LEVEL"] = os.environ.get("KCFG_KIVY_LOG_LEVEL", "warning")
os.environ['KIVY_AUDIO'] = "sdl2" # force working audio
@@ -481,6 +484,8 @@ class KaTrainApp(MDApp):
sys.exit(0)
def run_app():
app = KaTrainApp()
signal.signal(signal.SIGINT, app.signal_handler)
@@ -488,9 +493,24 @@ def run_app():
try:
app.run()
except Exception as e:
print(e)
app.on_request_close()
raise
print(f"FATAL ERROR: {e}")
traceback.print_exc()
if __name__ == "__main__":
class CrashHandler(ExceptionHandler):
def handle_exception(self, inst):
args = list(inst.args)
trace = traceback.format_exc()
message = args[0]
app = MDApp.get_running_app()
if app and app.gui:
app.gui.log("Exception: " + message + "\n" + trace,OUTPUT_ERROR)
else:
print("Exception: " + message + "\n" + trace)
return ExceptionManager.PASS
ExceptionManager.add_handler(CrashHandler())
run_app()