Changeset 934ce649 in sasview for src/sas/sascalc


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

File:
1 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 
Note: See TracChangeset for help on using the changeset viewer.