1.1 --- a/pprocess.py Sat Jul 07 22:12:30 2007 +0000
1.2 +++ b/pprocess.py Sat Jul 07 22:12:30 2007 +0000
1.3 @@ -6,20 +6,18 @@
1.4
1.5 Copyright (C) 2005, 2006, 2007 Paul Boddie <paul@boddie.org.uk>
1.6
1.7 -This software is free software; you can redistribute it and/or
1.8 -modify it under the terms of the GNU General Public License as
1.9 -published by the Free Software Foundation; either version 2 of
1.10 -the License, or (at your option) any later version.
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU Lesser General Public License as published by the Free
1.13 +Software Foundation; either version 3 of the License, or (at your option) any
1.14 +later version.
1.15
1.16 -This software is distributed in the hope that it will be useful,
1.17 -but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 -GNU General Public License for more details.
1.20 +This program is distributed in the hope that it will be useful, but WITHOUT
1.21 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.22 +FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
1.23 +details.
1.24
1.25 -You should have received a copy of the GNU General Public
1.26 -License along with this library; see the file LICENCE.txt
1.27 -If not, write to the Free Software Foundation, Inc.,
1.28 -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
1.29 +You should have received a copy of the GNU Lesser General Public License along
1.30 +with this program. If not, see <http://www.gnu.org/licenses/>.
1.31
1.32 --------
1.33
1.34 @@ -35,7 +33,7 @@
1.35 To create new processes to run a function or any callable object, specify the
1.36 "callable" and any arguments as follows:
1.37
1.38 -channel = start(fn, arg1, arg2, named1=value1, named2=value2)
1.39 +channel = pprocess.start(fn, arg1, arg2, named1=value1, named2=value2)
1.40
1.41 This returns a channel which can then be used to communicate with the created
1.42 process. Meanwhile, in the created process, the given callable will be invoked
1.43 @@ -80,8 +78,8 @@
1.44 an Exchange object, optionally initialising it with a list of channels through
1.45 which data is expected to arrive:
1.46
1.47 -exchange = Exchange() # populate the exchange later
1.48 -exchange = Exchange(channels) # populate the exchange with channels
1.49 +exchange = pprocess.Exchange() # populate the exchange later
1.50 +exchange = pprocess.Exchange(channels) # populate the exchange with channels
1.51
1.52 We can add channels to the exchange using the add method:
1.53
1.54 @@ -111,7 +109,7 @@
1.55 A convenient form of message exchanges can be adopted by defining a subclass of
1.56 the Exchange class and defining a particular method:
1.57
1.58 -class MyExchange(Exchange):
1.59 +class MyExchange(pprocess.Exchange):
1.60 def store_data(self, channel):
1.61 data = channel.receive()
1.62 # Do something with data here.
1.63 @@ -131,7 +129,13 @@
1.64 exchange.add_wait(channel) # add a channel, waiting if the limit would be
1.65 # exceeded
1.66
1.67 -We can explicitly wait for "free space" for channels by calling the wait method:
1.68 +We can even start processes and monitor channels without ever handling the
1.69 +channel ourselves:
1.70 +
1.71 +exchange.start(fn, arg1, arg2, named1=value1, named2=value2)
1.72 +
1.73 +We can explicitly wait for "free space" for channels by calling the wait method,
1.74 +although the start and add_wait methods make this less interesting:
1.75
1.76 exchange.wait()
1.77
1.78 @@ -171,7 +175,7 @@
1.79 http://www.greenend.org.uk/rjk/2001/06/poll.html
1.80 """
1.81
1.82 -__version__ = "0.2.4"
1.83 +__version__ = "0.2.5"
1.84
1.85 import os
1.86 import sys
1.87 @@ -411,6 +415,18 @@
1.88
1.89 raise NotImplementedError, "store_data"
1.90
1.91 + # Convenience methods.
1.92 +
1.93 + def start(self, callable, *args, **kwargs):
1.94 +
1.95 + """
1.96 + Using pprocess.start, create a new process for the given 'callable'
1.97 + using any additional arguments provided. Then, monitor the channel
1.98 + created between this process and the created process.
1.99 + """
1.100 +
1.101 + self.add_wait(start(callable, *args, **kwargs))
1.102 +
1.103 def create():
1.104
1.105 """