Opened 8 years ago

Closed 7 years ago

#869 closed defect (fixed)

fit page computation thread cleanup

Reported by: pkienzle Owned by:
Priority: major Milestone: SasView 4.2.0
Component: SasView Keywords:
Cc: Work Package: SasView Bug Fixing

Description

Should only allow a single computation thread at a time on a fit page. Specifically, it makes no sense to hit a 1D or 2D model while a fit is going on in the same page is not sensible. Maybe the page should be disabled except for a stop but while the fit is in progress?

It is useful to let a fit run in the background for one model while preparing another model for fitting.

Change History (5)

comment:1 Changed 8 years ago by pkienzle

Instead of using CallAfter to trigger the computation in the fitting perspective, we could instead put a cancellable timer in _draw_model1D/_draw_model2D/fit. If there has been a requests in the past 100 ms (and if the existing calculation has not yet stopped), then reset the timer, otherwise go ahead and start the calc thread.

The logic would be something like the following:

def __init__(...):
   self.delay_timer = wx.Timer()
   wx.Bind(self.delay_timer, self._on_timer)
   self.compute_lock = thread.allocate_lock()
   self.compute_running = False

def compute_when_idle(...):
   if self.delay_timer.IsRunning():
       self.delay_timer.Stop()

   with self.compute_lock:
       if self.compute_running:
          self.compute_abort = True

   self.compute_request = ...

   self.delay_timer.Start()

def _on_timer(self, event):
   with self.compute_lock:
       if self.compute_running:
           # continue delay until current calc has stopped
           self.delay_timer.Start(CALC_DELAY, oneShot=True)
           return

       self.compute_abort = False
       self.compute_running = True

   thread.start_new_thread(run_computation, self.compute_request)

def stop_requested(self):
   with self.compute_lock:
       return self.compute_abort

def run_computation(self, request):
   try:
       # this is running in another thread
       ... run the request using self.stop_requested as the abort test ...
       ... signal that new results are available for display ...        
   except Exception:
       post any errors to the console
   finally:
       with self.compute_lock:
           self.compute_running = False

comment:2 Changed 8 years ago by pkienzle

Note: no way to stop a fit in progress if the controlling fit page has been closed.

comment:3 Changed 8 years ago by pkienzle

  • Milestone changed from SasView 4.1.0 to SasView 4.2.0

comment:4 Changed 8 years ago by pkienzle

The proposed fix will also address ticket #14 since the request to recompute the model as each parameter is set will be ignored until after the final parameter is set.

comment:5 Changed 7 years ago by krzywon

  • Resolution set to fixed
  • Status changed from new to closed

The recompute issue was handled in PR109.

Note: See TracTickets for help on using tickets.