1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23   
 24   
 25  """Module containing command objects sent from the slaves back to the master.""" 
 26   
 27   
 28  import sys 
 29   
 30   
 31  from multi.misc import raise_unimplemented, Result, Result_string 
 32   
 33   
 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): 
  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   
 72 -    def __init__(self, processor, result_commands, io_data=None, completed=True): 
  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           
 90          processor.assert_on_master() 
 91   
 92           
 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) 
 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): 
  121   
122   
123   
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