Module pprocess :: Class Exchange
[hide private]
[frames] | no frames]

Class Exchange

source code

Known Subclasses:
Map, Queue


A communications exchange that can be used to detect channels which are
ready to communicate. Subclasses of this class can define the 'store_data'
method in order to enable the 'add_wait', 'wait' and 'finish' methods.



Instance Methods [hide private]
 
__init__(self, channels=None, limit=None, reuse=0, autoclose=1)
Initialise the exchange with an optional list of 'channels'.
source code
 
add(self, channel)
Add the given 'channel' to the exchange.
source code
 
active(self)
Return a list of active channels.
source code
 
ready(self, timeout=None)
Wait for a period of time specified by the optional 'timeout' (or until communication is possible) and return a list of channels which are ready to be read from.
source code
 
remove(self, channel)
Remove the given 'channel' from the exchange.
source code
 
add_wait(self, channel)
Add the given 'channel' to the exchange, waiting if the limit on active channels would be exceeded by adding the channel.
source code
 
wait(self)
Test for the limit on channels, blocking and reading incoming data until the number of channels is below the limit.
source code
 
start_waiting(self, channel)
Start a waiting process given the reception of data on the given 'channel'.
source code
 
finish(self)
Finish the use of the exchange by waiting for all channels to complete.
source code
 
store(self)
For each ready channel, process the incoming data.
source code
 
store_data(self, channel)
Store incoming data from the specified 'channel'.
source code
 
start(self, callable, *args, **kw)
Using pprocess.start, create a new process for the given 'callable' using any additional arguments provided.
source code
 
create(self)
Using pprocess.create, create a new process and return the created communications channel to the created process.
source code
 
manage(self, callable)
Wrap the given 'callable' in an object which can then be called in the same way as 'callable', but with new processes and communications managed automatically.
source code
Method Details [hide private]

__init__(self, channels=None, limit=None, reuse=0, autoclose=1)
(Constructor)

source code 

Initialise the exchange with an optional list of 'channels'.

If the optional 'limit' is specified, restrictions on the addition of
new channels can be enforced and observed through the 'add_wait', 'wait'
and 'finish' methods. To make use of these methods, create a subclass of
this class and define a working 'store_data' method.

If the optional 'reuse' parameter is set to a true value, channels and
processes will be reused for waiting computations.

If the optional 'autoclose' parameter is set to a false value, channels
will not be closed automatically when they are removed from the exchange
- by default they are closed when removed.

store_data(self, channel)

source code 

Store incoming data from the specified 'channel'. In subclasses of this
class, such data could be stored using instance attributes.

start(self, callable, *args, **kw)

source code 

Using pprocess.start, create a new process for the given 'callable'
using any additional arguments provided. Then, monitor the channel
created between this process and the created process.

create(self)

source code 

Using pprocess.create, create a new process and return the created
communications channel to the created process. In the creating process,
return None - the channel receiving data from the created process will
be automatically managed by this exchange.