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