1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23   
 24  """Module containing command objects sent from the master to the slaves.""" 
 25   
 26   
 27  import sys 
 28   
 29   
 30  from multi.misc import raise_unimplemented, Result, Result_string 
 31   
 32   
 34      """A command to executed remotely on the slave processor - designed to be subclassed by users. 
 35   
 36      The command should be queued with the command queue using the add_to_queue command of the master 
 37      and B{must} return at least one Result_command even if it is a processor.NULL_RESULT. Results 
 38      are returned from the Slave_command to the master processor using the return_object method of 
 39      the processor passed to the command. Any exceptions raised will be caught wrapped and returned 
 40      to the master processor by the slave processor. 
 41   
 42      @note:  Good examples of subclassing a slave command include multi.commands.MF_minimise_command 
 43              and multi.commands.Get_name_command. 
 44      @see:   multi.commands.MF_minimise_command. 
 45      @see:   multi.commands.Get_name_command. 
 46      """ 
 47   
 50   
 51   
 52 -    def run(self, processor, completed): 
  53          """Run the slave command on the slave processor 
 54           
 55          This is a base method which must be overridden. 
 56   
 57          The run command B{must} return at least one Result_command even if it is a processor.NULL_RESULT.  Results are returned from the Slave_command to the master processor using the return_object method of the processor passed to the command. Any exceptions raised will be caught wrapped and returned to the master processor by the slave processor. 
 58   
 59   
 60          @param processor:   The slave processor the command is running on.  Results from the command are returned via calls to processor.return_object. 
 61          @type processor:    Processor instance 
 62          @param completed:   The flag used in batching result returns to indicate that the sequence of batched result commands has completed. This value should be returned via the last result object retuned by this method or methods it calls. All other Result_commands should be initialised with completed=False. This is an optimisation to prevent the sending an extra batched result queue completion result command being sent, it may be an over early optimisation. 
 63          @type completed:    bool 
 64          """ 
 65   
 66           
 67          raise_unimplemented(self.run) 
  68   
 69   
 71          """Called by the master processor to remember this Slave_commands memo. 
 72   
 73          @param memo:    The memo to remember, memos are remembered by getting the memo_id of the 
 74                          memo. 
 75          """ 
 76   
 77          if memo != None: 
 78              self.memo_id = memo.memo_id() 
 79          else: 
 80              self.memo_id = None 
   81   
 82   
 83   
 85      """Special command for terminating slave processors. 
 86   
 87      This sets the processor's do_quit flag, terminating the Processor.run() loop for the slaves. 
 88      """ 
 89   
 90 -    def run(self, processor, completed): 
  91          """Set the slave processor's do_quit flag to terminate. 
 92   
 93          @param processor:   The slave processor the command is running on.  Results from the command are returned via calls to processor.return_object. 
 94          @type processor:    Processor instance 
 95          @param completed:   The flag used in batching result returns to indicate that the sequence of batched result commands has completed.  This value should be returned via the last result object retuned by this method or methods it calls. All other Result_commands should be initialised with completed=False.  This is an optimisation to prevent the sending an extra batched result queue completion result command being sent, it may be an over early optimisation. 
 96          @type completed:    bool 
 97          """ 
 98   
 99           
100          processor.return_object(processor.NULL_RESULT) 
101   
102           
103          processor.do_quit = True 
  104   
105   
106   
108      """Special command for sending data for storage on the slaves.""" 
109   
119   
120   
121 -    def add(self, name, value): 
 122          """Pump in data to be held and transfered to the slave by the command. 
123   
124          @keyword name:  The name of the data structure to store. 
125          @type name:     str 
126          @keyword value: The data structure. 
127          @type value:    anything 
128          """ 
129   
130           
131          self.names.append(name) 
132          self.values.append(value) 
 133   
134   
136          """Remove all data from the slave.""" 
137   
138           
139          self.names = [] 
140          self.values = [] 
 141   
142   
143 -    def run(self, processor, completed): 
 144          """Set the slave processor's do_quit flag to terminate. 
145   
146          @param processor:   The slave processor the command is running on.  Results from the command are returned via calls to processor.return_object. 
147          @type processor:    Processor instance 
148          @param completed:   The flag used in batching result returns to indicate that the sequence of batched result commands has completed.  This value should be returned via the last result object retuned by this method or methods it calls. All other Result_commands should be initialised with completed=False.  This is an optimisation to prevent the sending an extra batched result queue completion result command being sent, it may be an over early optimisation. 
149          @type completed:    bool 
150          """ 
151   
152           
153          processor.return_object(processor.NULL_RESULT) 
154   
155           
156          for i in range(len(self.names)): 
157              setattr(processor.data_store, self.names[i], self.values[i]) 
158   
159           
160          self.clear() 
  161