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

Source Code for Module gui.analyses.execute

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2010-2011 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program 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 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Module docstring. 
 23  """Module containing the class for threaded and non-threaded analysis execution.""" 
 24   
 25  # Python module imports. 
 26  import sys 
 27  from threading import Thread 
 28  from traceback import print_exc 
 29   
 30  # relax module imports. 
 31  from lib.errors import RelaxImplementError 
 32  from status import Status; status = Status() 
 33   
 34   
35 -class Execute(Thread):
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 # Store the args. 52 self.gui = gui 53 self.data = data 54 self.data_index = data_index 55 56 # Threaded execution. 57 if thread: 58 # Set up the thread object. 59 Thread.__init__(self) 60 61 # Set the thread to be daemonic so that relax can exit. 62 self.daemon = True 63 64 # No treaded execution. 65 else: 66 # Alias the a few dummy methods. 67 self.join = self._join 68 self.start = self._start
69 70
71 - def _join(self):
72 """Dummy join() method for non-threaded execution."""
73 74
75 - def _start(self):
76 """Replacement start() method for when execution is not threaded.""" 77 78 # Execute the run() method. 79 self.run()
80 81
82 - def run(self):
83 """Execute the thread (or pseudo-thread).""" 84 85 # Execute the analysis, catching errors. 86 try: 87 self.run_analysis() 88 89 # Handle all errors. 90 except: 91 # Place the analysis index and execution info into the exception queue. 92 status.exception_queue.put([self.data_index, sys.exc_info()]) 93 94 # Print the exception. 95 sys.stderr.write("Exception raised in thread.\n\n") 96 print_exc() 97 sys.stderr.write("\n\n\n") 98 sys.stderr.flush() 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