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-2012 Edward d'Auvergne                                   # 
  5  #                                                                             # 
  6  # This file is part of the program relax.                                     # 
  7  #                                                                             # 
  8  # relax 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 2 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # relax 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 relax; if not, write to the Free Software                        # 
 20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 21  #                                                                             # 
 22  ############################################################################### 
 23   
 24  # Module docstring. 
 25  """Module containing command objects sent from the slaves back to the master.""" 
 26   
 27  # Python module imports. 
 28  import sys 
 29   
 30  # multi module imports. 
 31  from multi.misc import raise_unimplemented, Result, Result_string 
 32   
 33   
34 -class Result_command(Result):
35 """A general result command - designed to be subclassed by users. 36 37 This is a general result command from a Slave command that will have its run() method called on 38 return to the master processor. 39 40 @see: multi.processor.Slave_command. 41 """ 42
43 - def __init__(self, processor, completed, memo_id=None):
44 #TODO: check this method is documnted by its parent 45 super(Result_command, self).__init__(processor=processor, completed=completed) 46 self.memo_id = memo_id
47 48
49 - def run(self, processor, memo):
50 """The run method of the result command. 51 52 This method will be called when the result command is processed by the master and should 53 carry out any actions the slave command needs carried out on the master (e.g. save or 54 register results). 55 56 @see: multi.processor.Processor. 57 @see: multi.processor.Slave_command. 58 @see: multi.memo.Memo. 59 60 @param processor: The master processor that queued the original Slave_command. 61 @type processor: Processor instance 62 @param memo: A memo that was registered when the original slave command was placed on 63 the queue. This provides local storage on the master. 64 @type memo: Memo instance or None 65 """ 66 67 pass
68 69 70
71 -class Batched_result_command(Result_command):
72 - def __init__(self, processor, result_commands, io_data=None, completed=True):
73 super(Batched_result_command, self).__init__(processor=processor, completed=completed) 74 self.result_commands = result_commands 75 76 # Store the IO data to print out via the run() method called by the master. 77 self.io_data = io_data
78 79
80 - def run(self, processor, batched_memo):
81 """The results command to be run by the master. 82 83 @param processor: The processor instance. 84 @type processor: Processor instance 85 @param batched_memo: The batched memo object. 86 @type batched_memo: Memo instance 87 """ 88 89 # First check that we are on the master. 90 processor.assert_on_master() 91 92 # Unravel the IO stream data on the master in the correct order. 93 for line, stream in self.io_data: 94 if stream == 0: 95 sys.stdout.write(line) 96 else: 97 sys.stderr.write(line) 98 99 if batched_memo != None: 100 msg = "batched result commands shouldn't have memo values, memo: " + repr(batched_memo) 101 102 if batched_memo != None: 103 msg = "batched result commands shouldn't have memo values, memo: " + repr(batched_memo) 104 raise ValueError(msg) 105 106 for result_command in self.result_commands: 107 processor.process_result(result_command)
108 109 110
111 -class Null_result_command(Result_command):
112 """An empty result command. 113 114 This command should be returned from slave_command if no other Result_command is returned. This 115 allows the queue processor to register that the slave processor has completed its processing and 116 schedule new Slave-commands to it. 117 """ 118
119 - def __init__(self, processor, completed=True):
120 super(Null_result_command, self).__init__(processor=processor, completed=completed)
121 122 123
124 -class Result_exception(Result_command):
125 """Return and raise an exception from the salve processor.""" 126
127 - def __init__(self, processor, exception, completed=True):
128 """Initialise the result command with an exception. 129 130 @param exception: An exception that was raised on the slave processor (note the real 131 exception will be wrapped in a Capturing_exception. 132 @type exception: Exception instance 133 """ 134 135 super(Result_exception, self).__init__(processor=processor, completed=completed) 136 self.exception = exception
137 138
139 - def run(self, processor, memo):
140 """Raise the exception from the Slave_processor.""" 141 142 raise self.exception
143