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 from multi.misc import raise_unimplemented
28
29
31 """A command to executed remotely on the slave processor - designed to be subclassed by users.
32
33 The command should be queued with the command queue using the add_to_queue command of the master
34 and B{must} return at least one Result_command even if it is a processor.NULL_RESULT. Results
35 are returned from the Slave_command to the master processor using the return_object method of
36 the processor passed to the command. Any exceptions raised will be caught wrapped and returned
37 to the master processor by the slave processor.
38
39 @note: Good examples of subclassing a slave command include multi.commands.MF_minimise_command
40 and multi.commands.Get_name_command.
41 @see: multi.commands.MF_minimise_command.
42 @see: multi.commands.Get_name_command.
43 """
44
47
48
49 - def run(self, processor, completed):
50 """Run the slave command on the slave processor
51
52 This is a base method which must be overridden.
53
54 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.
55
56
57 @param processor: The slave processor the command is running on. Results from the command are returned via calls to processor.return_object.
58 @type processor: Processor instance
59 @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.
60 @type completed: bool
61 """
62
63
64 raise_unimplemented(self.run)
65
66
68 """Called by the master processor to remember this Slave_commands memo.
69
70 @param memo: The memo to remember, memos are remembered by getting the memo_id of the
71 memo.
72 """
73
74 if memo != None:
75 self.memo_id = memo.memo_id()
76 else:
77 self.memo_id = None
78
79
80
82 """Special command for terminating slave processors.
83
84 This sets the processor's do_quit flag, terminating the Processor.run() loop for the slaves.
85 """
86
87 - def run(self, processor, completed):
88 """Set the slave processor's do_quit flag to terminate.
89
90 @param processor: The slave processor the command is running on. Results from the command are returned via calls to processor.return_object.
91 @type processor: Processor instance
92 @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.
93 @type completed: bool
94 """
95
96
97 processor.return_object(processor.NULL_RESULT)
98
99
100 processor.do_quit = True
101
102
103
105 """Special command for sending data for storage on the slaves."""
106
116
117
118 - def add(self, name, value):
119 """Pump in data to be held and transfered to the slave by the command.
120
121 @keyword name: The name of the data structure to store.
122 @type name: str
123 @keyword value: The data structure.
124 @type value: anything
125 """
126
127
128 self.names.append(name)
129 self.values.append(value)
130
131
133 """Remove all data from the slave."""
134
135
136 self.names = []
137 self.values = []
138
139
140 - def run(self, processor, completed):
141 """Set the slave processor's do_quit flag to terminate.
142
143 @param processor: The slave processor the command is running on. Results from the command are returned via calls to processor.return_object.
144 @type processor: Processor instance
145 @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.
146 @type completed: bool
147 """
148
149
150 processor.return_object(processor.NULL_RESULT)
151
152
153 for i in range(len(self.names)):
154 setattr(processor.data_store, self.names[i], self.values[i])
155
156
157 self.clear()
158