Changeset 934ce649 in sasview


Ignore:
Timestamp:
May 23, 2016 4:48:46 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
b6f563b4
Parents:
52b7fd9
Message:

make sure errors in compute get reported to user

Location:
src/sas
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/data_util/calcthread.py

    rb699768 r934ce649  
    119119 
    120120    def __init__(self, completefn=None, updatefn=None, 
    121                  yieldtime=0.01, worktime=0.01): 
     121                 yieldtime=0.01, worktime=0.01, 
     122                 exception_handler=None): 
    122123        """Prepare the calculator""" 
    123124        self.yieldtime     = yieldtime 
     
    125126        self.completefn    = completefn 
    126127        self.updatefn      = updatefn 
     128        self.exception_handler = exception_handler 
    127129        self._interrupting = False 
    128130        self._running      = False 
     
    199201 
    200202    def update(self, **kwargs): 
    201  
    202203        """Update GUI with the lastest results from the current work unit.""" 
    203204        if self.updatefn != None and clock() > self._time_for_update: 
     
    225226        """Perform a work unit.  The subclass will provide details of 
    226227        the arguments.""" 
    227         raise NotImplemented, "Calculation thread needs compute method" 
     228        raise NotImplemented("Calculation thread needs compute method") 
     229 
     230    def exception(self): 
     231        """ 
     232        An exception occurred during computation, so call the exception handler 
     233        if there is one.  If not, then log the exception and continue. 
     234        """ 
     235        # If we have an exception handler, let it try to handle the exception. 
     236        # If it fails fall through to log the failure to handle the exception 
     237        # (the original exception will be lost).  If there is no exception 
     238        # handler, just log the exception in compute that we are responding to. 
     239        if self.exception_handler: 
     240            try: 
     241                self.exception_handler(*sys.exc_info()) 
     242                return 
     243            except Exception: 
     244                pass 
     245        import logging 
     246        logging.error(traceback.format_exc()) 
     247        #print 'CalcThread exception', 
    228248 
    229249    def _run(self): 
     
    250270                pass 
    251271            except: 
    252                 traceback.print_exc() 
    253                 #print 'CalcThread exception', 
     272                self.exception() 
    254273        self._running = False 
    255274 
  • src/sas/sasgui/perspectives/fitting/fitpage.py

    rcb4ef58 r934ce649  
    13301330                                              qmin=float(self.qmin_x), 
    13311331                                              qmax=float(self.qmax_x), 
    1332                                               enable_smearer=enable_smearer, 
    1333                                               draw=True) 
     1332                                              enable_smearer=enable_smearer) 
    13341333                if flag: 
    13351334                    #self.compute_chisqr(smearer= temp_smearer) 
     
    26062605                     qmin=float(self.qmin_x), 
    26072606                     qmax=float(self.qmax_x), 
    2608                      enable_smearer=enable_smearer, 
    2609                      draw=True) 
     2607                     enable_smearer=enable_smearer) 
    26102608 
    26112609        self.state.enable_smearer = self.enable_smearer.GetValue() 
  • src/sas/sasgui/perspectives/fitting/fitting.py

    r243fbc0 r934ce649  
    1919import time 
    2020from copy import deepcopy 
    21 import models 
     21import traceback 
    2222 
    2323from sas.sascalc.dataloader.loader import Loader 
     
    4545from sas.sasgui.guiframe.gui_manager import MDIFrame 
    4646from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
     47 
     48from . import models 
    4749 
    4850MAX_NBR_DATA = 4 
     
    260262                msg += "and try it again." 
    261263                wx.MessageBox(msg, 'Info') 
    262                 #wx.PostEvent(self.parent, StatusEvent(status=msg, type='stop', 
    263                 #                                      info='warning')) 
     264                #evt = StatusEvent(status=msg, type='stop', info='warning') 
     265                #wx.PostEvent(self.parent, evt) 
    264266            else: 
    265267                self.delete_menu.Delete(event_id) 
     
    268270                        self.edit_menu.DeleteItem(item) 
    269271                        msg = "The custom model, %s, has been deleted." % label 
    270                         wx.PostEvent(self.parent, StatusEvent(status=msg, 
    271                                                 type='stop', info='info')) 
     272                        evt = StatusEvent(status=msg, type='stop', info='info') 
     273                        wx.PostEvent(self.parent, evt) 
    272274                        break 
    273275        except: 
     
    579581            except: 
    580582                msg = "Fitting: cannot deal with the theory received" 
     583                evt = StatusEvent(status=msg, info="error") 
    581584                logging.error("set_theory " + msg + "\n" + str(sys.exc_value)) 
    582                 wx.PostEvent(self.parent, 
    583                              StatusEvent(status=msg, info="error")) 
     585                wx.PostEvent(self.parent, evt) 
    584586 
    585587    def set_state(self, state=None, datainfo=None, format=None): 
     
    968970                    if not page.param_toFit: 
    969971                        msg = "No fitting parameters for %s" % page.window_caption 
    970                         wx.PostEvent(page.parent.parent, 
    971                                      StatusEvent(status=msg, info="error", 
    972                                                  type="stop")) 
     972                        evt = StatusEvent(status=msg, info="error", type="stop") 
     973                        wx.PostEvent(page.parent.parent, evt) 
    973974                        return False 
    974975                    if not page._update_paramv_on_fit(): 
     
    976977                        msg += " invalid in %s" % \ 
    977978                                    page.window_caption 
    978                         wx.PostEvent(page.parent.parent, 
    979                                      StatusEvent(status=msg, info="error", 
    980                                      type="stop")) 
     979                        evt = StatusEvent(status=msg, info="error", type="stop") 
     980                        wx.PostEvent(page.parent.parent, evt) 
    981981                        return False 
    982982 
     
    999999            except KeyboardInterrupt: 
    10001000                msg = "Fitting terminated" 
    1001                 wx.PostEvent(self.parent, StatusEvent(status=msg, info="info", 
    1002                                                       type="stop")) 
     1001                evt = StatusEvent(status=msg, info="info", type="stop") 
     1002                wx.PostEvent(self.parent, evt) 
    10031003                return True 
    10041004            except: 
    10051005                raise 
    10061006                msg = "Fitting error: %s" % str(sys.exc_value) 
    1007                 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", 
    1008                                                       type="stop")) 
     1007                evt = StatusEvent(status=msg, info="error", type="stop") 
     1008                wx.PostEvent(self.parent, evt) 
    10091009                return False 
    10101010        ## If a thread is already started, stop it 
     
    11011101            # add data associated to the page created 
    11021102            if page != None: 
    1103                 wx.PostEvent(self.parent, StatusEvent(status="Page Created", 
    1104                                                info="info")) 
     1103                evt = StatusEvent(status="Page Created", info="info") 
     1104                wx.PostEvent(self.parent, evt) 
    11051105            else: 
    11061106                msg = "Page was already Created" 
    1107                 wx.PostEvent(self.parent, StatusEvent(status=msg, 
    1108                                                        info="warning")) 
     1107                evt = StatusEvent(status=msg, info="warning") 
     1108                wx.PostEvent(self.parent, evt) 
    11091109        except: 
    11101110            msg = "Creating Fit page: %s" % sys.exc_value 
     
    12681268        msg = "Fit completed on %s \n" % str_time 
    12691269        msg += "Duration time: %s s.\n" % str(elapsed) 
    1270         wx.PostEvent(self.parent, StatusEvent(status=msg, info="info", 
    1271                                               type="stop")) 
     1270        evt = StatusEvent(status=msg, info="info", type="stop") 
     1271        wx.PostEvent(self.parent, evt) 
    12721272 
    12731273        if batch_outputs is None: 
     
    14191419                                         batch_inputs=batch_inputs) 
    14201420 
    1421         wx.PostEvent(self.parent, StatusEvent(status=msg, error="info", 
    1422                                               type="stop")) 
     1421        evt = StatusEvent(status=msg, error="info", type="stop") 
     1422        wx.PostEvent(self.parent, evt) 
    14231423        # Remove parameters that are not shown 
    14241424        cpage = self.fit_panel.get_page_by_id(uid) 
     
    14991499        msg = "Fit completed on %s \n" % str_time 
    15001500        msg += "Duration time: %s s.\n" % str(elapsed) 
    1501         wx.PostEvent(self.parent, StatusEvent(status=msg, info="info", 
    1502                                                       type="stop")) 
     1501        evt = StatusEvent(status=msg, info="info", type="stop") 
     1502        wx.PostEvent(self.parent, evt) 
    15031503        wx.PostEvent(self.result_panel, PlotResultEvent(result=result)) 
    15041504        wx.CallAfter(self._update_fit_button, page_id) 
     
    15241524                    not numpy.all(numpy.isfinite(res.pvec)): 
    15251525                    msg = "Fitting did not converge!!!" 
    1526                     wx.PostEvent(self.parent, 
    1527                              StatusEvent(status=msg, 
    1528                                          info="warning", 
    1529                                          type="stop")) 
     1526                    evt = StatusEvent(status=msg, info="warning", type="stop") 
     1527                    wx.PostEvent(self.parent, evt) 
    15301528                    wx.CallAfter(self._update_fit_button, page_id) 
    15311529                else: 
     
    15511549                    except KeyboardInterrupt: 
    15521550                        msg = "Singular point: Fitting Stoped." 
    1553                         wx.PostEvent(self.parent, StatusEvent(status=msg, 
    1554                                                               info="info", 
    1555                                                               type="stop")) 
     1551                        evt = StatusEvent(status=msg, info="info", type="stop") 
     1552                        wx.PostEvent(self.parent, evt) 
    15561553                    except: 
    15571554                        msg = "Singular point: Fitting Error occurred." 
    1558                         wx.PostEvent(self.parent, StatusEvent(status=msg, 
    1559                                                               info="error", 
    1560                                                               type="stop")) 
     1555                        evt = StatusEvent(status=msg, info="error", type="stop") 
     1556                        wx.PostEvent(self.parent, evt) 
    15611557 
    15621558        except: 
     
    15641560                   % sys.exc_value) 
    15651561            #import traceback; msg = "\n".join((traceback.format_exc(), msg)) 
    1566             wx.PostEvent(self.parent, StatusEvent(status=msg, info="warning", 
    1567                                                   type="stop")) 
     1562            evt = StatusEvent(status=msg, info="warning", type="stop") 
     1563            wx.PostEvent(self.parent, evt) 
    15681564 
    15691565    def _update_fit_button(self, page_id): 
     
    16021598        ## post a message to status bar 
    16031599        msg = "Set Chain Fitting: %s" % str(not self.batch_reset_flag) 
    1604         wx.PostEvent(self.parent, 
    1605                      StatusEvent(status=msg)) 
     1600        wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    16061601 
    16071602 
     
    17491744            raise 
    17501745 
     1746    def _calc_exception(self, etype, value, tb): 
     1747        """ 
     1748        Handle exception from calculator by posting it as an error. 
     1749        """ 
     1750        logging.error("".join(traceback.format_exception(etype, value, tb))) 
     1751        msg = traceback.format_exception(etype, value, tb, limit=1) 
     1752        evt = StatusEvent(status="".join(msg), type="stop", info="error") 
     1753        wx.PostEvent(self.parent, evt) 
     1754 
    17511755    def _update2D(self, output, time=None): 
    17521756        """ 
    17531757        Update the output of plotting model 
    17541758        """ 
    1755         wx.PostEvent(self.parent, StatusEvent(status="Plot \ 
    1756         #updating ... ", type="update")) 
    1757         #self.ready_fit() 
     1759        msg = "Plot updating ... " 
     1760        wx.PostEvent(self.parent, StatusEvent(msg, type="update")) 
    17581761 
    17591762    def _complete2D(self, image, data, model, page_id, elapsed, index, qmin, 
     
    18611864                    time.sleep(0.1) 
    18621865            self.calc_2D = Calc2D(model=model, 
    1863                                     data=data, 
    1864                                     page_id=page_id, 
    1865                                     smearer=smearer, 
    1866                                     qmin=qmin, 
    1867                                     qmax=qmax, 
    1868                                     weight=weight, 
    1869                                     fid=fid, 
    1870                                     toggle_mode_on=toggle_mode_on, 
    1871                                     state=state, 
    1872                                     completefn=self._complete2D, 
    1873                                     update_chisqr=update_chisqr, source=source) 
     1866                                  data=data, 
     1867                                  page_id=page_id, 
     1868                                  smearer=smearer, 
     1869                                  qmin=qmin, 
     1870                                  qmax=qmax, 
     1871                                  weight=weight, 
     1872                                  fid=fid, 
     1873                                  toggle_mode_on=toggle_mode_on, 
     1874                                  state=state, 
     1875                                  completefn=self._complete2D, 
     1876                                  update_chisqr=update_chisqr, 
     1877                                  exception_handler=self._calc_exception, 
     1878                                  source=source) 
    18741879            self.calc_2D.queue() 
    18751880        except: 
     
    19261931                                  #updatefn = self._update1D, 
    19271932                                  update_chisqr=update_chisqr, 
     1933                                  exception_handler=self._calc_exception, 
    19281934                                  source=source) 
    19291935            self.calc_1D.queue() 
  • src/sas/sasgui/perspectives/fitting/model_thread.py

    rd85c194 r934ce649  
    2525                 source='model', 
    2626                 yieldtime=0.04, 
    27                  worktime=0.04 
     27                 worktime=0.04, 
     28                 exception_handler=None, 
    2829                 ): 
    29         CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime) 
     30        CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime, 
     31                            exception_handler=exception_handler) 
    3032        self.qmin = qmin 
    3133        self.qmax = qmax 
     
    133135                 updatefn=None, 
    134136                 yieldtime=0.01, 
    135                  worktime=0.01 
     137                 worktime=0.01, 
     138                 exception_handler=None, 
    136139                 ): 
    137140        """ 
    138141        """ 
    139         CalcThread.__init__(self, completefn, 
    140                  updatefn, 
    141                  yieldtime, 
    142                  worktime) 
     142        CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime, 
     143                            exception_handler=exception_handler) 
    143144        self.fid = fid 
    144145        self.data = data 
Note: See TracChangeset for help on using the changeset viewer.