Changeset ded5e77 in sasview


Ignore:
Timestamp:
Apr 11, 2018 5:25:45 AM (6 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
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
Children:
a3221b6
Parents:
d6e38661
Message:

Thread stopping for supported optimizers SASVIEW-505

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    rd6e38661 rded5e77  
    191191        self.is_batch_fitting = False 
    192192        self.is_chain_fitting = False 
     193        # Is the fit job running? 
     194        self.fit_started=False 
     195        # The current fit thread 
     196        self.calc_fit = None 
    193197        # Current SasModel in view 
    194198        self.kernel_module = None 
     
    12001204        Perform fitting on the current data 
    12011205        """ 
     1206        if self.fit_started: 
     1207            self.stopFit() 
     1208            return 
     1209 
    12021210        # initialize fitter constants 
    12031211        fit_id = 0 
     
    12261234        completefn = self.batchFittingCompleted if self.is_batch_fitting else self.fittingCompleted 
    12271235 
    1228         calc_fit = FitThread(handler=handler, 
     1236        self.calc_fit = FitThread(handler=handler, 
    12291237                            fn=fitters, 
    12301238                            batch_inputs=batch_inputs, 
     
    12371245        if LocalConfig.USING_TWISTED: 
    12381246            # start the trhrhread with twisted 
    1239             calc_thread = threads.deferToThread(calc_fit.compute) 
     1247            calc_thread = threads.deferToThread(self.calc_fit.compute) 
    12401248            calc_thread.addCallback(completefn) 
    12411249            calc_thread.addErrback(self.fitFailed) 
    12421250        else: 
    12431251            # Use the old python threads + Queue 
    1244             calc_fit.queue() 
    1245             calc_fit.ready(2.5) 
     1252            self.calc_fit.queue() 
     1253            self.calc_fit.ready(2.5) 
    12461254 
    12471255        self.communicate.statusBarUpdateSignal.emit('Fitting started...') 
     1256        self.fit_started = True 
    12481257        # Disable some elements 
    12491258        self.setFittingStarted() 
    12501259 
     1260    def stopFit(self): 
     1261        """ 
     1262        Attempt to stop the fitting thread 
     1263        """ 
     1264        if self.calc_fit is None or not self.calc_fit.isrunning(): 
     1265            return 
     1266        self.calc_fit.stop() 
     1267        #self.fit_started=False 
     1268        #re-enable the Fit button 
     1269        self.setFittingStopped() 
     1270 
     1271        msg = "Fitting cancelled." 
     1272        self.communicate.statusBarUpdateSignal.emit(msg) 
     1273 
    12511274    def updateFit(self): 
    12521275        """ 
     
    12581281        """ 
    12591282        """ 
    1260         print("FIT FAILED: ", reason) 
    1261         pass 
     1283        self.setFittingStopped() 
     1284        msg = "Fitting failed with: "+ str(reason) 
     1285        self.communicate.statusBarUpdateSignal.emit(msg) 
    12621286 
    12631287    def batchFittingCompleted(self, result): 
     
    13091333 
    13101334        elapsed = result[1] 
    1311         msg = "Fitting completed successfully in: %s s.\n" % GuiUtils.formatNumber(elapsed) 
     1335        if self.calc_fit._interrupting: 
     1336            msg = "Fitting cancelled by user after: %s s." % GuiUtils.formatNumber(elapsed) 
     1337            logging.warning("\n"+msg+"\n") 
     1338        else: 
     1339            msg = "Fitting completed successfully in: %s s." % GuiUtils.formatNumber(elapsed) 
    13121340        self.communicate.statusBarUpdateSignal.emit(msg) 
    13131341 
     
    23862414    def setFittingStarted(self): 
    23872415        """ 
    2388         Set item enablement on fitting start 
    2389         """ 
    2390         #disable the Fit button 
    2391         self.cmdFit.setText('Running...') 
    2392         self.cmdFit.setEnabled(False) 
     2416        Set buttion caption on fitting start 
     2417        """ 
     2418        # Notify the user that fitting is being run 
     2419        # Allow for stopping the job 
     2420        self.cmdFit.setStyleSheet('QPushButton {color: red;}') 
     2421        self.cmdFit.setText('Stop fit') 
    23932422 
    23942423    def setFittingStopped(self): 
    23952424        """ 
    2396         Set item enablement on fitting stop 
    2397         """ 
    2398         #enable the Fit button 
     2425        Set button caption on fitting stop 
     2426        """ 
     2427        # Notify the user that fitting is available 
     2428        self.cmdFit.setStyleSheet('QPushButton {color: black;}') 
    23992429        self.cmdFit.setText("Fit") 
    2400         self.cmdFit.setEnabled(True) 
     2430        self.fit_started = False 
    24012431 
    24022432    def readFitPage(self, fp): 
Note: See TracChangeset for help on using the changeset viewer.