Package gui :: Package analyses :: Module execute
[hide private]
[frames] | no frames]

Source Code for Module gui.analyses.execute

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2011 Edward d'Auvergne                                        # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """Module containing the class for threaded and non-threaded analysis execution.""" 
 25   
 26  # Python module imports. 
 27  import sys 
 28  from threading import Thread 
 29  from traceback import print_exc 
 30   
 31  # relax module imports. 
 32  from relax_errors import RelaxImplementError 
 33  from status import Status; status = Status() 
 34   
 35   
36 -class Execute(Thread):
37 """The analysis execution object.""" 38
39 - def __init__(self, gui, data, data_index, thread=True):
40 """Set up the analysis execution object. 41 42 @param gui: The GUI object. 43 @type gui: wx object 44 @param data: The data container with all data for the analysis. 45 @type data: class instance 46 @param data_index: The index of the analysis in the relax data store. 47 @type data_index: int 48 @keyword thread: The flag for turning threading on and off. 49 @type thread: bool 50 """ 51 52 # Store the args. 53 self.gui = gui 54 self.data = data 55 self.data_index = data_index 56 57 # Threaded execution. 58 if thread: 59 # Set up the thread object. 60 Thread.__init__(self) 61 62 # Set the thread to be daemonic so that relax can exit. 63 self.daemon = True 64 65 # No treaded execution. 66 else: 67 # Alias the a few dummy methods. 68 self.join = self._join 69 self.start = self._start
70 71
72 - def _join(self):
73 """Dummy join() method for non-threaded execution."""
74 75
76 - def _start(self):
77 """Replacement start() method for when execution is not threaded.""" 78 79 # Execute the run() method. 80 self.run()
81 82
83 - def run(self):
84 """Execute the thread (or pseudo-thread).""" 85 86 # Execute the analysis, catching errors. 87 try: 88 self.run_analysis() 89 90 # Handle all errors. 91 except: 92 # Place the analysis index and execution info into the exception queue. 93 status.exception_queue.put([self.data_index, sys.exc_info()]) 94 95 # Print the exception. 96 sys.stderr.write("Exception raised in thread.\n\n") 97 print_exc() 98 sys.stderr.write("\n\n\n") 99 100 # Unlock the execution lock, if needed. 101 if status.exec_lock.locked(): 102 status.exec_lock.release()
103 104
105 - def run_analysis(self):
106 """Execute the analysis 107 108 This method must be overridden. 109 """ 110 111 raise RelaxImplementError
112