Communicating sequential processes, in Python.
When using CSP Python as a DSL, this module will normally be imported via the statement ‘from csp.cspprocess import *‘.
Copyright (C) Sarah Mount, 2008.
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.
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.
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
Implementation of CSP processes. Not intended to be used in client code. Use @process instead.
Implementation of CSP server processes. Not intended to be used in client code. Use @forever instead.
CSP select (OCCAM ALT) process.
What should happen if a guard is poisoned?
Poison the last selected guard and unlink from the guard list.
Sets self.last_selected to None.
Run CSP processes in parallel.
Run CSP processes sequentially.
Terminate the execution of this process.
FIXME: Remove this method.
Abstract class to represent CSP guards.
All methods must be overridden in subclasses.
CSP Channel objects.
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.
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.
Disable this channel for Alt selection.
MUST be called after L{enable} if this channel is not selected.
Enable a read for an Alt select.
MUST be called before L{select()} or L{is_selectable()}.
Channel objects using files on disk.
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.
Decorator to turn a function into a CSP process.
Note that the function itself will not be a CSPProcess object, but will generate a CSPProcess object when called.
Decorator to turn a function into a CSP server process.
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.