-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcspprocess.html
More file actions
395 lines (348 loc) · 19.9 KB
/
Copy pathcspprocess.html
File metadata and controls
395 lines (348 loc) · 19.9 KB
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CSP based on OS processes — python-csp v0.1 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '#',
VERSION: '0.1',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="python-csp v0.1 documentation" href="index.html" />
<link rel="next" title="CSP based on POSIX threads" href="cspthread.html" />
<link rel="prev" title="Welcome to python-csp’s documentation!" href="index.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="modindex.html" title="Global Module Index"
accesskey="M">modules</a> |</li>
<li class="right" >
<a href="cspthread.html" title="CSP based on POSIX threads"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="index.html" title="Welcome to python-csp’s documentation!"
accesskey="P">previous</a> |</li>
<li><a href="index.html">python-csp v0.1 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="module-cspprocess">
<h1>CSP based on OS processes<a class="headerlink" href="#module-cspprocess" title="Permalink to this headline">¶</a></h1>
<p>Communicating sequential processes, in Python.</p>
<p>When using CSP Python as a DSL, this module will normally be imported
via the statement ‘from csp.cspprocess import <a href="#id1"><span class="problematic" id="id2">*</span></a>‘.</p>
<p>Copyright (C) Sarah Mount, 2008.</p>
<p>This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.</p>
<p>This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.</p>
<p>You should have rceeived a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA</p>
<dl class="class">
<dt id="cspprocess.CSPProcess">
<em class="property">class </em><tt class="descclassname">cspprocess.</tt><tt class="descname">CSPProcess</tt><big>(</big><em>func</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#cspprocess.CSPProcess" title="Permalink to this definition">¶</a></dt>
<dd><p>Implementation of CSP processes.
Not intended to be used in client code. Use @process instead.</p>
<dl class="method">
<dt id="cspprocess.CSPProcess.run">
<tt class="descname">run</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.CSPProcess.run" title="Permalink to this definition">¶</a></dt>
<dd>Called automatically when the L{start} methods is called.</dd></dl>
</dd></dl>
<dl class="class">
<dt id="cspprocess.CSPServer">
<em class="property">class </em><tt class="descclassname">cspprocess.</tt><tt class="descname">CSPServer</tt><big>(</big><em>func</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#cspprocess.CSPServer" title="Permalink to this definition">¶</a></dt>
<dd><p>Implementation of CSP server processes.
Not intended to be used in client code. Use @forever instead.</p>
<dl class="method">
<dt id="cspprocess.CSPServer.run">
<tt class="descname">run</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.CSPServer.run" title="Permalink to this definition">¶</a></dt>
<dd>Called automatically when the L{start} methods is called.</dd></dl>
</dd></dl>
<dl class="class">
<dt id="cspprocess.Alt">
<em class="property">class </em><tt class="descclassname">cspprocess.</tt><tt class="descname">Alt</tt><big>(</big><em>*args</em><big>)</big><a class="headerlink" href="#cspprocess.Alt" title="Permalink to this definition">¶</a></dt>
<dd><p>CSP select (OCCAM ALT) process.</p>
<p>What should happen if a guard is poisoned?</p>
<dl class="method">
<dt id="cspprocess.Alt.fair_select">
<tt class="descname">fair_select</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Alt.fair_select" title="Permalink to this definition">¶</a></dt>
<dd>Select a guard to synchronise with. Do not select the
previously selected guard (unless it is the only guard
available).</dd></dl>
<dl class="method">
<dt id="cspprocess.Alt.poison">
<tt class="descname">poison</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Alt.poison" title="Permalink to this definition">¶</a></dt>
<dd><p>Poison the last selected guard and unlink from the guard list.</p>
<p>Sets self.last_selected to None.</p>
</dd></dl>
<dl class="method">
<dt id="cspprocess.Alt.pri_select">
<tt class="descname">pri_select</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Alt.pri_select" title="Permalink to this definition">¶</a></dt>
<dd>Select a guard to synchronise with, in order of
“priority”. The guard with the lowest index in the L{guards}
list has the highest priority.</dd></dl>
<dl class="method">
<dt id="cspprocess.Alt.select">
<tt class="descname">select</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Alt.select" title="Permalink to this definition">¶</a></dt>
<dd>Randomly select from ready guards.</dd></dl>
</dd></dl>
<dl class="class">
<dt id="cspprocess.Par">
<em class="property">class </em><tt class="descclassname">cspprocess.</tt><tt class="descname">Par</tt><big>(</big><em>*procs</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#cspprocess.Par" title="Permalink to this definition">¶</a></dt>
<dd><p>Run CSP processes in parallel.</p>
<dl class="method">
<dt id="cspprocess.Par.start">
<tt class="descname">start</tt><big>(</big><em>timeout=None</em><big>)</big><a class="headerlink" href="#cspprocess.Par.start" title="Permalink to this definition">¶</a></dt>
<dd>Start then synchronize with the execution of parallel processes.
Return when all parallel processes have returned.</dd></dl>
<dl class="method">
<dt id="cspprocess.Par.terminate">
<tt class="descname">terminate</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Par.terminate" title="Permalink to this definition">¶</a></dt>
<dd>Terminate the execution of this process.</dd></dl>
</dd></dl>
<dl class="class">
<dt id="cspprocess.Seq">
<em class="property">class </em><tt class="descclassname">cspprocess.</tt><tt class="descname">Seq</tt><big>(</big><em>*procs</em><big>)</big><a class="headerlink" href="#cspprocess.Seq" title="Permalink to this definition">¶</a></dt>
<dd><p>Run CSP processes sequentially.</p>
<dl class="method">
<dt id="cspprocess.Seq.start">
<tt class="descname">start</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Seq.start" title="Permalink to this definition">¶</a></dt>
<dd>Start this process running.</dd></dl>
<dl class="method">
<dt id="cspprocess.Seq.stop">
<tt class="descname">stop</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Seq.stop" title="Permalink to this definition">¶</a></dt>
<dd><p>Terminate the execution of this process.</p>
<p>FIXME: Remove this method.</p>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="cspprocess.Guard">
<em class="property">class </em><tt class="descclassname">cspprocess.</tt><tt class="descname">Guard</tt><a class="headerlink" href="#cspprocess.Guard" title="Permalink to this definition">¶</a></dt>
<dd><p>Abstract class to represent CSP guards.</p>
<p>All methods must be overridden in subclasses.</p>
<dl class="method">
<dt id="cspprocess.Guard.disable">
<tt class="descname">disable</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Guard.disable" title="Permalink to this definition">¶</a></dt>
<dd>Roll back from an L{enable} call.</dd></dl>
<dl class="method">
<dt id="cspprocess.Guard.enable">
<tt class="descname">enable</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Guard.enable" title="Permalink to this definition">¶</a></dt>
<dd>Prepare for, but do not commit to a synchronisation.</dd></dl>
<dl class="method">
<dt id="cspprocess.Guard.is_selectable">
<tt class="descname">is_selectable</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Guard.is_selectable" title="Permalink to this definition">¶</a></dt>
<dd>Should return C{True} if this guard can be selected by an L{Alt}.</dd></dl>
<dl class="method">
<dt id="cspprocess.Guard.poison">
<tt class="descname">poison</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Guard.poison" title="Permalink to this definition">¶</a></dt>
<dd>Terminate all processes attached to this guard.</dd></dl>
<dl class="method">
<dt id="cspprocess.Guard.select">
<tt class="descname">select</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Guard.select" title="Permalink to this definition">¶</a></dt>
<dd>Commit to a synchronisation started by L{enable}.</dd></dl>
</dd></dl>
<dl class="class">
<dt id="cspprocess.Channel">
<em class="property">class </em><tt class="descclassname">cspprocess.</tt><tt class="descname">Channel</tt><a class="headerlink" href="#cspprocess.Channel" title="Permalink to this definition">¶</a></dt>
<dd><p>CSP Channel objects.</p>
<p>In python-csp there are two sorts of channel. In JCSP terms these
are Any2Any, Alting channels. However, each channel creates an
operating system level pipe. Since this is a file object the
number of channels a program can create is limited to the maximum
number of files the operating system allows to be open at any one
time. To avoid this bottleneck use L{FileChannel} objects, which
close the file descriptor used for IPC after every read or write
operations. Read and write operations are, however, over 20 time
slower when performed on L{FileChannel} objects.</p>
<p>Subclasses of C{Channel} must call L{_setup()} in their
constructor and override L{put}, L{get}, L{__del__},
L{__getstate__} and L{__setstate__}, the latter two methods for
pickling.</p>
<dl class="method">
<dt id="cspprocess.Channel.disable">
<tt class="descname">disable</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Channel.disable" title="Permalink to this definition">¶</a></dt>
<dd><p>Disable this channel for Alt selection.</p>
<p>MUST be called after L{enable} if this channel is not selected.</p>
</dd></dl>
<dl class="method">
<dt id="cspprocess.Channel.enable">
<tt class="descname">enable</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Channel.enable" title="Permalink to this definition">¶</a></dt>
<dd><p>Enable a read for an Alt select.</p>
<p>MUST be called before L{select()} or L{is_selectable()}.</p>
</dd></dl>
<dl class="method">
<dt id="cspprocess.Channel.get">
<tt class="descname">get</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Channel.get" title="Permalink to this definition">¶</a></dt>
<dd>Get a Python object from a process-safe store.</dd></dl>
<dl class="method">
<dt id="cspprocess.Channel.is_selectable">
<tt class="descname">is_selectable</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Channel.is_selectable" title="Permalink to this definition">¶</a></dt>
<dd>Test whether Alt can select this channel.</dd></dl>
<dl class="method">
<dt id="cspprocess.Channel.poison">
<tt class="descname">poison</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Channel.poison" title="Permalink to this definition">¶</a></dt>
<dd>Poison a channel causing all processes using it to terminate.</dd></dl>
<dl class="method">
<dt id="cspprocess.Channel.put">
<tt class="descname">put</tt><big>(</big><em>item</em><big>)</big><a class="headerlink" href="#cspprocess.Channel.put" title="Permalink to this definition">¶</a></dt>
<dd>Put C{item} on a process-safe store.</dd></dl>
<dl class="method">
<dt id="cspprocess.Channel.read">
<tt class="descname">read</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Channel.read" title="Permalink to this definition">¶</a></dt>
<dd>Read (and return) a Python object from this channel.</dd></dl>
<dl class="method">
<dt id="cspprocess.Channel.resume">
<tt class="descname">resume</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Channel.resume" title="Permalink to this definition">¶</a></dt>
<dd>Resume this mobile channel after migrating between processes.</dd></dl>
<dl class="method">
<dt id="cspprocess.Channel.select">
<tt class="descname">select</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Channel.select" title="Permalink to this definition">¶</a></dt>
<dd>Complete a Channel read for an Alt select.</dd></dl>
<dl class="method">
<dt id="cspprocess.Channel.suspend">
<tt class="descname">suspend</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.Channel.suspend" title="Permalink to this definition">¶</a></dt>
<dd>Suspend this mobile channel before migrating between processes.</dd></dl>
<dl class="method">
<dt id="cspprocess.Channel.write">
<tt class="descname">write</tt><big>(</big><em>obj</em><big>)</big><a class="headerlink" href="#cspprocess.Channel.write" title="Permalink to this definition">¶</a></dt>
<dd>Write a Python object to this channel.</dd></dl>
</dd></dl>
<dl class="class">
<dt id="cspprocess.FileChannel">
<em class="property">class </em><tt class="descclassname">cspprocess.</tt><tt class="descname">FileChannel</tt><a class="headerlink" href="#cspprocess.FileChannel" title="Permalink to this definition">¶</a></dt>
<dd><p>Channel objects using files on disk.</p>
<p>C{FileChannel} objects close their files after each read or write
operation. The advantage of this is that client code can create as
many C{FileChannel} objects as it wishes (unconstrained by the
operating system’s maximum number of open files). In return there
is a performance hit – reads and writes are around 10 x slower on
C{FileChannel} objects compared to L{Channel} objects.</p>
<dl class="method">
<dt id="cspprocess.FileChannel.get">
<tt class="descname">get</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.FileChannel.get" title="Permalink to this definition">¶</a></dt>
<dd>Get a Python object from a process-safe store.</dd></dl>
<dl class="method">
<dt id="cspprocess.FileChannel.put">
<tt class="descname">put</tt><big>(</big><em>item</em><big>)</big><a class="headerlink" href="#cspprocess.FileChannel.put" title="Permalink to this definition">¶</a></dt>
<dd>Put C{item} on a process-safe store.</dd></dl>
<dl class="method">
<dt id="cspprocess.FileChannel.resume">
<tt class="descname">resume</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.FileChannel.resume" title="Permalink to this definition">¶</a></dt>
<dd>Suspend this mobile channel after migrating between processes.</dd></dl>
<dl class="method">
<dt id="cspprocess.FileChannel.suspend">
<tt class="descname">suspend</tt><big>(</big><big>)</big><a class="headerlink" href="#cspprocess.FileChannel.suspend" title="Permalink to this definition">¶</a></dt>
<dd>Suspend this mobile channel before migrating between processes.</dd></dl>
</dd></dl>
<dl class="function">
<dt id="cspprocess.process">
<tt class="descclassname">cspprocess.</tt><tt class="descname">process</tt><big>(</big><em>func</em><big>)</big><a class="headerlink" href="#cspprocess.process" title="Permalink to this definition">¶</a></dt>
<dd><p>Decorator to turn a function into a CSP process.</p>
<p>Note that the function itself will not be a CSPProcess object, but
will generate a CSPProcess object when called.</p>
</dd></dl>
<dl class="function">
<dt id="cspprocess.forever">
<tt class="descclassname">cspprocess.</tt><tt class="descname">forever</tt><big>(</big><em>func</em><big>)</big><a class="headerlink" href="#cspprocess.forever" title="Permalink to this definition">¶</a></dt>
<dd><p>Decorator to turn a function into a CSP server process.</p>
<p>It is preferable to use this rather than @process, to enable the
CSP tracer to terminate correctly and produce a CSP model, or
other debugging information.</p>
</dd></dl>
</div>
<div class="section" id="indices-and-tables">
<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
<ul class="simple">
<li><a class="reference external" href="genindex.html"><em>Index</em></a></li>
<li><a class="reference external" href="modindex.html"><em>Module Index</em></a></li>
<li><a class="reference external" href="search.html"><em>Search Page</em></a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="index.html">
<img class="logo" src="_static/pythoncsp-docs.png" alt="Logo"/>
</a></p>
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference external" href="#">CSP based on OS processes</a></li>
<li><a class="reference external" href="#indices-and-tables">Indices and tables</a></li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="index.html"
title="previous chapter">Welcome to python-csp’s documentation!</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="cspthread.html"
title="next chapter">CSP based on POSIX threads</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/cspprocess.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="modindex.html" title="Global Module Index"
>modules</a> |</li>
<li class="right" >
<a href="cspthread.html" title="CSP based on POSIX threads"
>next</a> |</li>
<li class="right" >
<a href="index.html" title="Welcome to python-csp’s documentation!"
>previous</a> |</li>
<li><a href="index.html">python-csp v0.1 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2010, Sarah Mount.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.4.
</div>
</body>
</html>