aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-12-05 14:32:13 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-12-05 14:48:52 -0500
commit139274f0bbb0cd36e4bf1b858ea14da3b7859c2a (patch)
treea50a0dcfba9c07d6d20c3a27ccc8fbac5228c685
parent72161d04053e168baf025957ec75008d0fd4f60f (diff)
downloadkutter-139274f0bbb0cd36e4bf1b858ea14da3b7859c2a.tar.gz
kutter-139274f0bbb0cd36e4bf1b858ea14da3b7859c2a.tar.xz
kutter-139274f0bbb0cd36e4bf1b858ea14da3b7859c2a.zip
mathutil: Propagate errors from background_coordinate_descent()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--klippy/mathutil.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/klippy/mathutil.py b/klippy/mathutil.py
index ed330c61..82f12b9c 100644
--- a/klippy/mathutil.py
+++ b/klippy/mathutil.py
@@ -3,7 +3,7 @@
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import math, logging, multiprocessing
+import math, logging, multiprocessing, traceback
######################################################################
@@ -51,8 +51,13 @@ def coordinate_descent(adj_params, params, error_func):
def background_coordinate_descent(printer, adj_params, params, error_func):
parent_conn, child_conn = multiprocessing.Pipe()
def wrapper():
- res = coordinate_descent(adj_params, params, error_func)
- child_conn.send(res)
+ try:
+ res = coordinate_descent(adj_params, params, error_func)
+ except:
+ child_conn.send((True, traceback.format_exc()))
+ child_conn.close()
+ return
+ child_conn.send((False, res))
child_conn.close()
# Start a process to perform the calculation
calc_proc = multiprocessing.Process(target=wrapper)
@@ -68,7 +73,9 @@ def background_coordinate_descent(printer, adj_params, params, error_func):
gcode.respond_info("Working on calibration...", log=False)
eventtime = reactor.pause(eventtime + .1)
# Return results
- res = parent_conn.recv()
+ is_err, res = parent_conn.recv()
+ if is_err:
+ raise Exception("Error in coordinate descent: %s" % (res,))
calc_proc.join()
parent_conn.close()
return res