From 2b139fb4ba38cd949bf2bf2dd272417a1e39c05c Mon Sep 17 00:00:00 2001 From: rozyczko Date: Wed, 8 Jan 2025 15:25:23 +0100 Subject: [PATCH] foolproof the fitter against bump's antics --- src/sas/qtgui/Perspectives/Fitting/FitThread.py | 14 ++++++++++++-- .../qtgui/Perspectives/Fitting/FittingWidget.py | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/sas/qtgui/Perspectives/Fitting/FitThread.py b/src/sas/qtgui/Perspectives/Fitting/FitThread.py index 84dfc476f3..a470792e45 100644 --- a/src/sas/qtgui/Perspectives/Fitting/FitThread.py +++ b/src/sas/qtgui/Perspectives/Fitting/FitThread.py @@ -13,10 +13,20 @@ def map_getattr(classInstance, classFunc, *args): Take an instance of a class and a function name as a string. Execute class.function and return result """ - return getattr(classInstance, classFunc)(*args) + try: + return_value = getattr(classInstance, classFunc)(*args) + except Exception as ex: + logger.error("Fitting failed: %s", traceback.format_exc()) + return None + return return_value def map_apply(arguments): - return arguments[0](*arguments[1:]) + try: + return_value = arguments[0](*arguments[1:]) + except Exception as ex: + logger.error("Fitting failed: %s", traceback.format_exc()) + return None + return return_value class FitThread(CalcThread): """Thread performing the fit """ diff --git a/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py b/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py index 3a93a2cac8..4d63b40485 100644 --- a/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py +++ b/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py @@ -2108,9 +2108,11 @@ def fitComplete(self, result): #re-enable the Fit button self.enableInteractiveElements() - if len(result) == 0: + if result is None or len(result) == 0 or result[0] is None or len(result[0]) == 0 or result[0][0] is None or len(result[0][0]) == 0: msg = "Fitting failed." self.communicate.statusBarUpdateSignal.emit(msg) + # reload the kernel_module in case it's corrupted + self.kernel_module = copy.deepcopy(self.kernel_module_copy) return # Don't recalculate chi2 - it's in res.fitness already