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 slaves back to the master."""
25
26
27 import sys
28
29
30 from multi.misc import Result
31
32
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):
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
71 - def __init__(self, processor, result_commands, io_data=None, completed=True):
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
89 processor.assert_on_master()
90
91
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
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):
120
121
122
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