# HG changeset patch # User paulb # Date 1189556047 0 # Node ID cf69e1e19964ef2554c4cad32510386b93438f89 # Parent 750186b3ecc1983a995f955f3adb7b61b9c93867 [project @ 2007-09-12 00:14:07 by paulb] Fixed the Map class to wrap callables, thus providing compatibility with the standard map function and normal callables. Added a limit to the pmap function. Updated release notes. diff -r 750186b3ecc1 -r cf69e1e19964 README.txt --- a/README.txt Tue Sep 11 22:49:29 2007 +0000 +++ b/README.txt Wed Sep 12 00:14:07 2007 +0000 @@ -70,7 +70,8 @@ automatically managed by the exchange from which they were acquired. * Added MakeParallel: a wrapper instantiated around a normal function which sends the result of that function over the supplied channel when invoked. - * Added a Map class which attempts to emulate the built-in map function. + * Added a Map class which attempts to emulate the built-in map function, + along with a pmap function using this class. * Extended and updated the examples. New in parallel 0.2.5 (Changes since parallel 0.2.4) diff -r 750186b3ecc1 -r cf69e1e19964 pprocess.py --- a/pprocess.py Tue Sep 11 22:49:29 2007 +0000 +++ b/pprocess.py Wed Sep 12 00:14:07 2007 +0000 @@ -517,7 +517,9 @@ def __call__(self, callable, sequence): - "Invoke 'callable' for each element in the 'sequence'." + "Wrap and invoke 'callable' for each element in the 'sequence'." + + wrapped = MakeParallel(callable) # Remember the channel addition order to order output. @@ -525,7 +527,7 @@ self.results = {} for i in sequence: - self.start(callable, *i) + self.start(wrapped, *i) self.finish() # NOTE: Could use a generator instead. @@ -613,11 +615,14 @@ except OSError: pass -def pmap(callable, sequence): +def pmap(callable, sequence, limit=None): - "A parallel version of the built-in map function." + """ + A parallel version of the built-in map function with an optional process + 'limit'. + """ - mymap = Map() + mymap = Map(limit=limit) return mymap(callable, sequence) # vim: tabstop=4 expandtab shiftwidth=4