# HG changeset patch # User paulb # Date 1183846350 0 # Node ID 3b3d14bea0c44a39017a60cc04185a9f8a5029e8 # Parent f998de52200e036dbf0f94d5fabe2b87e5ab8804 [project @ 2007-07-07 22:12:30 by paulb] Updated release information. Relicensed under the LGPLv3. Added a start method on the Exchange class. diff -r f998de52200e -r 3b3d14bea0c4 pprocess.py --- a/pprocess.py Sat Jul 07 22:12:30 2007 +0000 +++ b/pprocess.py Sat Jul 07 22:12:30 2007 +0000 @@ -6,20 +6,18 @@ Copyright (C) 2005, 2006, 2007 Paul Boddie -This software 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 free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License as published by the Free +Software Foundation; either version 3 of the License, or (at your option) any +later version. -This software 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. +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 Lesser General Public License for more +details. -You should have received a copy of the GNU General Public -License along with this library; see the file LICENCE.txt -If not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +You should have received a copy of the GNU Lesser General Public License along +with this program. If not, see . -------- @@ -35,7 +33,7 @@ To create new processes to run a function or any callable object, specify the "callable" and any arguments as follows: -channel = start(fn, arg1, arg2, named1=value1, named2=value2) +channel = pprocess.start(fn, arg1, arg2, named1=value1, named2=value2) This returns a channel which can then be used to communicate with the created process. Meanwhile, in the created process, the given callable will be invoked @@ -80,8 +78,8 @@ an Exchange object, optionally initialising it with a list of channels through which data is expected to arrive: -exchange = Exchange() # populate the exchange later -exchange = Exchange(channels) # populate the exchange with channels +exchange = pprocess.Exchange() # populate the exchange later +exchange = pprocess.Exchange(channels) # populate the exchange with channels We can add channels to the exchange using the add method: @@ -111,7 +109,7 @@ A convenient form of message exchanges can be adopted by defining a subclass of the Exchange class and defining a particular method: -class MyExchange(Exchange): +class MyExchange(pprocess.Exchange): def store_data(self, channel): data = channel.receive() # Do something with data here. @@ -131,7 +129,13 @@ exchange.add_wait(channel) # add a channel, waiting if the limit would be # exceeded -We can explicitly wait for "free space" for channels by calling the wait method: +We can even start processes and monitor channels without ever handling the +channel ourselves: + +exchange.start(fn, arg1, arg2, named1=value1, named2=value2) + +We can explicitly wait for "free space" for channels by calling the wait method, +although the start and add_wait methods make this less interesting: exchange.wait() @@ -171,7 +175,7 @@ http://www.greenend.org.uk/rjk/2001/06/poll.html """ -__version__ = "0.2.4" +__version__ = "0.2.5" import os import sys @@ -411,6 +415,18 @@ raise NotImplementedError, "store_data" + # Convenience methods. + + def start(self, callable, *args, **kwargs): + + """ + 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. + """ + + self.add_wait(start(callable, *args, **kwargs)) + def create(): """