delegate.py - delegation of work to multiple processes
Ka-Ping Yee, 15 December 1999
This module provides generic mechanisms for delegating work items.
At the moment, the main delegation mechanism is running work items in
parallel in child processes. Call 'parallelize' with a function and a
list of items to start the work. Here is an example:
def work(arg): return arg * 3
from delegate import parallelize
print parallelize(work, [2, 5, "a", 7])
The function must return a value that can be pickled so that it can be
communicated back to the parent. Most kinds of Python objects can be
pickled, including instances of custom classes as long as the class
allows the __init__ constructor to be called with no arguments. See
the 'pickle' module for details. The results are returned in a
dictionary that maps each item to its result.
The 'parallelize' function accepts an optional 'reporter' parameter
with which you can provide callbacks when jobs start and finish. See
the documentation on 'parallelize' and the Reporter class for details.
The 'timeout' function will run a job in a child process in order to
limit its running time. Here is an example:
from delegate import timeout
print timeout(work, 30) # this will print 5 after 10 seconds
print timeout(work, 5) # this will print None after 5 seconds
See the documentation string on 'timeout' for details.
|BEGIN = 2|
EXIT = 3
FAIL = 1
SUCCESS = 0