File: kiwi.tasklet.Tasklet.html

package info (click to toggle)
kiwi 1.9.22-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 11,976 kB
  • ctags: 5,619
  • sloc: python: 15,767; ansic: 193; xml: 77; makefile: 53; sh: 18
file content (337 lines) | stat: -rw-r--r-- 11,580 bytes parent folder | download | duplicates (3)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>API docs for &ldquo;kiwi.tasklet.Tasklet&rdquo;</title>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
    <link href="apidocs.css" type="text/css" rel="stylesheet" />
    
    
  </head>
  <body>
    <h1 class="class">Class k.t.Tasklet(<span title="object">object</span>):</h1>
    <p>
      <span id="part">Part of <a href="kiwi.html">kiwi</a>.<a href="kiwi.tasklet.html">tasklet</a></span>
      
      <a href="classIndex.html#kiwi.tasklet.Tasklet">View In Hierarchy</a>
    </p>
    <div>
      
    </div>
    <div>An object that launches and manages a tasklet.
<table class="fieldTable"><tr class="fieldStart"><td class="fieldName">Instance Variables</td><td class="fieldArg">state</td><td>current execution state of the tasklet, one of the STATE_* contants.
</td></tr><tr><td></td><td class="fieldArg">return_value</td><td>the value returned by the task function, or None.
</td></tr><tr class="fieldStart"><td class="fieldName">Class Variables</td><td class="fieldArg">STATE_RUNNING</td><td>the tasklet function is currently executing code
</td></tr><tr><td></td><td class="fieldArg">STATE_SUSPENDED</td><td>the tasklet function is currently waiting for an event
</td></tr><tr><td></td><td class="fieldArg">STATE_MSGSEND</td><td>the tasklet function is currently sending a message
</td></tr><tr><td></td><td class="fieldArg">STATE_ZOMBIE</td><td>the tasklet function has ended
</td></tr></table></div>
    
    
    <div id="splitTables">
      <table class="children sortable" id="id394">
  
  
  
  
  <tr class="method">
    
    
    <td>Method</td>
    <td><a href="kiwi.tasklet.Tasklet.html#__init__">__init__</a></td>
    <td><span>Launch a generator tasklet.
</span></td>
  </tr><tr class="method">
    
    
    <td>Method</td>
    <td><a href="kiwi.tasklet.Tasklet.html#start">start</a></td>
    <td><span>Starts the execution of the task, for use with tasklets
</span></td>
  </tr><tr class="method">
    
    
    <td>Method</td>
    <td><a href="kiwi.tasklet.Tasklet.html#get_message_actions">get_message_actions</a></td>
    <td><span>Dictionary mapping message names to actions ('accept' or
</span></td>
  </tr><tr class="method">
    
    
    <td>Method</td>
    <td><a href="kiwi.tasklet.Tasklet.html#run">run</a></td>
    <td><span>Method that executes the task.
</span></td>
  </tr><tr class="method">
    
    
    <td>Method</td>
    <td><a href="kiwi.tasklet.Tasklet.html#_invoke">_invoke</a></td>
    <td><span class="undocumented">Undocumented</span></td>
  </tr><tr class="method">
    
    
    <td>Method</td>
    <td><a href="kiwi.tasklet.Tasklet.html#_next_round">_next_round</a></td>
    <td><span class="undocumented">Undocumented</span></td>
  </tr><tr class="method">
    
    
    <td>Method</td>
    <td><a href="kiwi.tasklet.Tasklet.html#_dispatch_message">_dispatch_message</a></td>
    <td><span>get next message that a tasklet wants to receive; discard
</span></td>
  </tr><tr class="method">
    
    
    <td>Method</td>
    <td><a href="kiwi.tasklet.Tasklet.html#_update_wait_conditions">_update_wait_conditions</a></td>
    <td><span>disarm wait conditions removed and arm new wait conditions
</span></td>
  </tr><tr class="method">
    
    
    <td>Method</td>
    <td><a href="kiwi.tasklet.Tasklet.html#wait_condition_fired">wait_condition_fired</a></td>
    <td><span>Method that should be called when a wait condition fires
</span></td>
  </tr><tr class="method">
    
    
    <td>Method</td>
    <td><a href="kiwi.tasklet.Tasklet.html#add_join_callback">add_join_callback</a></td>
    <td><span>Add a callable to be invoked when the tasklet finishes.
</span></td>
  </tr><tr class="method">
    
    
    <td>Method</td>
    <td><a href="kiwi.tasklet.Tasklet.html#remove_join_callback">remove_join_callback</a></td>
    <td><span>Remove a join callback previously added with <a 
href="kiwi.tasklet.Tasklet.html#add_join_callback"><code>add_join_callback</code></a>
</span></td>
  </tr><tr class="method">
    
    
    <td>Method</td>
    <td><a href="kiwi.tasklet.Tasklet.html#_join">_join</a></td>
    <td><span class="undocumented">Undocumented</span></td>
  </tr><tr class="method">
    
    
    <td>Method</td>
    <td><a href="kiwi.tasklet.Tasklet.html#send_message">send_message</a></td>
    <td><span>Send a message to be received by the tasklet as an event.
</span></td>
  </tr>
  
</table>
      
      
    </div>
    
    
    
    <div class="function">
        <a name="kiwi.tasklet.Tasklet.__init__"></a>
        <a name="__init__"></a>
        <div class="functionHeader">
        
        def __init__(self, gen=None, start=True):
        
      </div>
        <div class="functionBody">
          
          <div>Launch a generator tasklet.
<table class="fieldTable"><tr class="fieldStart"><td class="fieldName">Parameters</td><td class="fieldArg">gen</td><td>a generator object that implements the tasklet main body
</td></tr><tr><td></td><td class="fieldArg">start</td><td><p>whether to automatically start running the tasklet in the 
constructor</p>
If `gen` is omitted or None, <a 
href="kiwi.tasklet.Tasklet.html#run"><code>run</code></a> should be 
overridden in a subclass.
</td></tr></table></div>
        </div>
      </div><div class="function">
        <a name="kiwi.tasklet.Tasklet.start"></a>
        <a name="start"></a>
        <div class="functionHeader">
        
        def start(self):
        
      </div>
        <div class="functionBody">
          
          <div>Starts the execution of the task, for use with tasklets created with 
start=False
<table class="fieldTable"></table></div>
        </div>
      </div><div class="function">
        <a name="kiwi.tasklet.Tasklet.get_message_actions"></a>
        <a name="get_message_actions"></a>
        <div class="functionHeader">
        
        def get_message_actions(self):
        
      </div>
        <div class="functionBody">
          
          <div>Dictionary mapping message names to actions ('accept' or 'discard' or 
'defer').  Should normally not be accessed directly by the programmer.
<table class="fieldTable"></table></div>
        </div>
      </div><div class="function">
        <a name="kiwi.tasklet.Tasklet.run"></a>
        <a name="run"></a>
        <div class="functionHeader">
        
        def run(self):
        
      </div>
        <div class="functionBody">
          
          <div><p>Method that executes the task.</p>
Should be overridden in a subclass if no generator is passed into the 
constructor.
<table class="fieldTable"><tr class="fieldStart"><td class="fieldName">Note</td><td colspan="2">do NOT call this method directly; it is meant to be called by the 
tasklet framework.
</td></tr></table></div>
        </div>
      </div><div class="function">
        <a name="kiwi.tasklet.Tasklet._invoke"></a>
        <a name="_invoke"></a>
        <div class="functionHeader">
        
        def _invoke(self):
        
      </div>
        <div class="functionBody">
          
          <div class="undocumented">Undocumented</div>
        </div>
      </div><div class="function">
        <a name="kiwi.tasklet.Tasklet._next_round"></a>
        <a name="_next_round"></a>
        <div class="functionHeader">
        
        def _next_round(self):
        
      </div>
        <div class="functionBody">
          
          <div class="undocumented">Undocumented</div>
        </div>
      </div><div class="function">
        <a name="kiwi.tasklet.Tasklet._dispatch_message"></a>
        <a name="_dispatch_message"></a>
        <div class="functionHeader">
        
        def _dispatch_message(self):
        
      </div>
        <div class="functionBody">
          
          <div>get next message that a tasklet wants to receive; discard messages that 
should be discarded
<table class="fieldTable"></table></div>
        </div>
      </div><div class="function">
        <a name="kiwi.tasklet.Tasklet._update_wait_conditions"></a>
        <a name="_update_wait_conditions"></a>
        <div class="functionHeader">
        
        def _update_wait_conditions(self, old_wait_list):
        
      </div>
        <div class="functionBody">
          
          <div>disarm wait conditions removed and arm new wait conditions
<table class="fieldTable"></table></div>
        </div>
      </div><div class="function">
        <a name="kiwi.tasklet.Tasklet.wait_condition_fired"></a>
        <a name="wait_condition_fired"></a>
        <div class="functionHeader">
        
        def wait_condition_fired(self, triggered_cond):
        
      </div>
        <div class="functionBody">
          
          <div>Method that should be called when a wait condition fires
<table class="fieldTable"></table></div>
        </div>
      </div><div class="function">
        <a name="kiwi.tasklet.Tasklet.add_join_callback"></a>
        <a name="add_join_callback"></a>
        <div class="functionHeader">
        
        def add_join_callback(self, callback, *extra_args):
        
      </div>
        <div class="functionBody">
          
          <div><p>Add a callable to be invoked when the tasklet finishes. Return a 
connection handle that can be used in remove_join_callback()</p>
The callback will be called like this:
<pre class="literalblock">
     callback(tasklet, retval, *extra_args)
</pre>
<p>where tasklet is the tasklet that finished, and retval its return value 
(or None).</p>
When a join callback is invoked, it is automatically removed, so calling
<a 
href="kiwi.tasklet.Tasklet.html#remove_join_callback"><code>remove_join_callback</code></a>
afterwards produces a KeyError exception.
<table class="fieldTable"></table></div>
        </div>
      </div><div class="function">
        <a name="kiwi.tasklet.Tasklet.remove_join_callback"></a>
        <a name="remove_join_callback"></a>
        <div class="functionHeader">
        
        def remove_join_callback(self, handle):
        
      </div>
        <div class="functionBody">
          
          <div>Remove a join callback previously added with <a 
href="kiwi.tasklet.Tasklet.html#add_join_callback"><code>add_join_callback</code></a>
<table class="fieldTable"></table></div>
        </div>
      </div><div class="function">
        <a name="kiwi.tasklet.Tasklet._join"></a>
        <a name="_join"></a>
        <div class="functionHeader">
        
        def _join(self, retval):
        
      </div>
        <div class="functionBody">
          
          <div class="undocumented">Undocumented</div>
        </div>
      </div><div class="function">
        <a name="kiwi.tasklet.Tasklet.send_message"></a>
        <a name="send_message"></a>
        <div class="functionHeader">
        
        def send_message(self, message):
        
      </div>
        <div class="functionBody">
          
          <div>Send a message to be received by the tasklet as an event.
<table class="fieldTable"><tr class="fieldStart"><td class="fieldName">Note</td><td colspan="2">Don't call this from another tasklet, only from the main loop!  To send 
a message from another tasklet, yield a <a 
href="kiwi.tasklet.Message.html"><code>Message</code></a> with a correctly 
set 'dest' parameter.
</td></tr></table></div>
        </div>
      </div>
    
    <address>
      <a href="index.html">API Documentation</a> for Kiwi, generated by <a href="http://codespeak.net/~mwh/pydoctor/">pydoctor</a> at 2008-05-29 16:06:17.
    </address>
  </body>
</html>