diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2020-09-06 12:45:27 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2020-09-06 12:45:27 -0400 |
commit | c285f8b6cf4adc83396aa89f3105461935c2aff6 (patch) | |
tree | fa0477c753df804c47f039b2f106257b4e3291d9 /klippy/klippy.py | |
parent | 1cdf0d474d4d14727d808519e9705d0a56201602 (diff) | |
download | kutter-c285f8b6cf4adc83396aa89f3105461935c2aff6.tar.gz kutter-c285f8b6cf4adc83396aa89f3105461935c2aff6.tar.xz kutter-c285f8b6cf4adc83396aa89f3105461935c2aff6.zip |
klippy: Improve handling of reactor.run() exceptions
Try to invoke a shutdown on an unhandled exception from reactor.run().
If that fails, try to do a clean exit.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/klippy.py')
-rw-r--r-- | klippy/klippy.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/klippy/klippy.py b/klippy/klippy.py index 6cac8099..3d090886 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -187,8 +187,17 @@ class Printer: try: self.reactor.run() except: - logging.exception("Unhandled exception during run") - return "error_exit" + msg = "Unhandled exception during run" + logging.exception(msg) + # Exception from a reactor callback - try to shutdown + try: + self.reactor.register_callback((lambda e: + self.invoke_shutdown(msg))) + self.reactor.run() + except: + logging.exception("Repeat unhandled exception during run") + # Another exception - try to exit + self.run_result = "error_exit" # Check restart flags run_result = self.run_result try: |