mathutil: Propagate errors from background_coordinate_descent()

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-12-05 14:32:13 -05:00
parent 72161d0405
commit 139274f0bb
1 changed files with 11 additions and 4 deletions

View File

@ -3,7 +3,7 @@
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net> # Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
# #
# This file may be distributed under the terms of the GNU GPLv3 license. # 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): def background_coordinate_descent(printer, adj_params, params, error_func):
parent_conn, child_conn = multiprocessing.Pipe() parent_conn, child_conn = multiprocessing.Pipe()
def wrapper(): def wrapper():
try:
res = coordinate_descent(adj_params, params, error_func) res = coordinate_descent(adj_params, params, error_func)
child_conn.send(res) except:
child_conn.send((True, traceback.format_exc()))
child_conn.close()
return
child_conn.send((False, res))
child_conn.close() child_conn.close()
# Start a process to perform the calculation # Start a process to perform the calculation
calc_proc = multiprocessing.Process(target=wrapper) 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) gcode.respond_info("Working on calibration...", log=False)
eventtime = reactor.pause(eventtime + .1) eventtime = reactor.pause(eventtime + .1)
# Return results # 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() calc_proc.join()
parent_conn.close() parent_conn.close()
return res return res