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

Class Exchange

source code

Known Subclasses:


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.

Once exchanges are populated with active channels, use of the principal
methods of the exchange typically cause the 'store' method to be invoked,
resulting in the processing of any incoming data.

Instance Methods [hide private]
 
__init__(self, channels=None, limit=None, reuse=0, continuous=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' in milliseconds (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
 
unfinished(self)
Return whether the exchange still has work scheduled or in progress.
source code
 
busy(self)
Return whether the exchange uses as many channels as it is allowed to.
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
 
finish(self)
Finish the use of the exchange by waiting for all channels to complete.
source code
 
store(self, timeout=None)
For each ready channel, process the incoming data.
source code
 
store_data(self, channel)
Store incoming data from the specified 'channel'.
source code
 
_get_waiting(self, channel)
Get waiting callable and argument information for new processes, given the reception of data on the given 'channel'.
source code
 
_set_waiting(self, callable, args, kw)
Support process creation by returning whether the given 'callable' has been queued for later invocation.
source code
 
_get_channel_for_process(self, channel)
Support process creation by returning the given 'channel' to the creating process, and None to the created process.
source code
 
start_waiting(self, channel)
Start a waiting process given the reception of data on the given 'channel'.
source code
 
start(self, callable, *args, **kw)
Create a new process for the given 'callable' using any additional arguments provided.
source code
 
create(self)
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, continuous=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, but the callable will
be invoked for each computation.

If the optional 'continuous' parameter is set to a true value, channels
and processes will be retained after receiving data sent from such
processes, since it will be assumed that they will communicate more
data.

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(self, timeout=None)

source code 

For each ready channel, process the incoming data. If the optional
'timeout' parameter (a duration in milliseconds) is specified, wait only
for the specified duration if no channels are ready to provide data.

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 

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 

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.