1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23  """Module containing the class for threaded and non-threaded analysis execution.""" 
 24   
 25   
 26  import sys 
 27  from threading import Thread 
 28  from traceback import print_exc 
 29   
 30   
 31  from lib.errors import RelaxImplementError 
 32  from status import Status; status = Status() 
 33   
 34   
 36      """The analysis execution object.""" 
 37   
 38 -    def __init__(self, gui, data, data_index, thread=True): 
  39          """Set up the analysis execution object. 
 40   
 41          @param gui:         The GUI object. 
 42          @type gui:          wx object 
 43          @param data:        The data container with all data for the analysis. 
 44          @type data:         class instance 
 45          @param data_index:  The index of the analysis in the relax data store. 
 46          @type data_index:   int 
 47          @keyword thread:    The flag for turning threading on and off. 
 48          @type thread:       bool 
 49          """ 
 50   
 51           
 52          self.gui = gui 
 53          self.data = data 
 54          self.data_index = data_index 
 55   
 56           
 57          if thread: 
 58               
 59              Thread.__init__(self) 
 60   
 61               
 62              self.daemon = True 
 63   
 64           
 65          else: 
 66               
 67              self.join = self._join 
 68              self.start = self._start 
  69   
 70   
 72          """Dummy join() method for non-threaded execution.""" 
  73   
 74   
 76          """Replacement start() method for when execution is not threaded.""" 
 77   
 78           
 79          self.run() 
  80   
 81   
 83          """Execute the thread (or pseudo-thread).""" 
 84   
 85           
 86          try: 
 87              self.run_analysis() 
 88   
 89           
 90          except: 
 91               
 92              status.exception_queue.put([self.data_index, sys.exc_info()]) 
 93   
 94               
 95              sys.stderr.write("Exception raised in thread.\n\n") 
 96              print_exc() 
 97              sys.stderr.write("\n\n\n") 
 98   
 99               
100              if status.exec_lock.locked(): 
101                  status.exec_lock.release() 
 102   
103   
105          """Execute the analysis 
106           
107          This method must be overridden. 
108          """ 
109   
110          raise RelaxImplementError 
  111