Package multi :: Module result_commands
[hide private]
[frames] | no frames]

Source Code for Module multi.result_commands

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007 Gary S Thompson (https://gna.org/users/varioustoxins)    # 
  4  # Copyright (C) 2008-2013 Edward d'Auvergne                                   # 
  5  #                                                                             # 
  6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  7  #                                                                             # 
  8  # This program is free software: you can redistribute it and/or modify        # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation, either version 3 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # This program is distributed in the hope that it will be useful,             # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """Module containing command objects sent from the slaves back to the master.""" 
 25   
 26  # Python module imports. 
 27  import sys 
 28   
 29  # multi module imports. 
 30  from multi.misc import Result 
 31   
 32   
33 -class Result_command(Result):
34 """A general result command - designed to be subclassed by users. 35 36 This is a general result command from a Slave command that will have its run() method called on 37 return to the master processor. 38 39 @see: multi.processor.Slave_command. 40 """ 41
42 - def __init__(self, processor, completed, memo_id=None):
43 #TODO: check this method is documnted by its parent 44 super(Result_command, self).__init__(processor=processor, completed=completed) 45 self.memo_id = memo_id
46 47
48 - def run(self, processor, memo):
49 """The run method of the result command. 50 51 This method will be called when the result command is processed by the master and should 52 carry out any actions the slave command needs carried out on the master (e.g. save or 53 register results). 54 55 @see: multi.processor.Processor. 56 @see: multi.processor.Slave_command. 57 @see: multi.memo.Memo. 58 59 @param processor: The master processor that queued the original Slave_command. 60 @type processor: Processor instance 61 @param memo: A memo that was registered when the original slave command was placed on 62 the queue. This provides local storage on the master. 63 @type memo: Memo instance or None 64 """ 65 66 pass
67 68 69
70 -class Batched_result_command(Result_command):
71 - def __init__(self, processor, result_commands, io_data=None, completed=True):
72 super(Batched_result_command, self).__init__(processor=processor, completed=completed) 73 self.result_commands = result_commands 74 75 # Store the IO data to print out via the run() method called by the master. 76 self.io_data = io_data
77 78
79 - def run(self, processor, batched_memo):
80 """The results command to be run by the master. 81 82 @param processor: The processor instance. 83 @type processor: Processor instance 84 @param batched_memo: The batched memo object. 85 @type batched_memo: Memo instance 86 """ 87 88 # First check that we are on the master. 89 processor.assert_on_master() 90 91 # Unravel the IO stream data on the master in the correct order. 92 for line, stream in self.io_data: 93 if stream == 0: 94 sys.stdout.write(line) 95 else: 96 sys.stderr.write(line) 97 98 if batched_memo != None: 99 msg = "batched result commands shouldn't have memo values, memo: " + repr(batched_memo) 100 101 if batched_memo != None: 102 msg = "batched result commands shouldn't have memo values, memo: " + repr(batched_memo) 103 raise ValueError(msg) 104 105 for result_command in self.result_commands: 106 processor.process_result(result_command)
107 108 109
110 -class Null_result_command(Result_command):
111 """An empty result command. 112 113 This command should be returned from slave_command if no other Result_command is returned. This 114 allows the queue processor to register that the slave processor has completed its processing and 115 schedule new Slave-commands to it. 116 """ 117
118 - def __init__(self, processor, completed=True):
119 super(Null_result_command, self).__init__(processor=processor, completed=completed)
120 121 122
123 -class Result_exception(Result_command):
124 """Return and raise an exception from the salve processor.""" 125
126 - def __init__(self, processor, exception, completed=True):
127 """Initialise the result command with an exception. 128 129 @param exception: An exception that was raised on the slave processor (note the real 130 exception will be wrapped in a Capturing_exception. 131 @type exception: Exception instance 132 """ 133 134 super(Result_exception, self).__init__(processor=processor, completed=completed) 135 self.exception = exception
136 137
138 - def run(self, processor, memo):
139 """Raise the exception from the Slave_processor.""" 140 141 raise self.exception
142