Logo Search packages:      
Sourcecode: calibre version File versions  Download package

calibre::utils::threadpool Namespace Reference


Detailed Description

Easy to use object-oriented thread pool framework.

A thread pool is an object that maintains a pool of worker threads to perform
time consuming operations in parallel. It assigns jobs to the threads
by putting them in a work request queue, where they are picked up by the
next available thread. This then performs the requested operation in the
background and puts the results in a another queue.

The thread pool object can then collect the results from all threads from
this queue as soon as they become available or after all threads have
finished their work. It's also possible, to define callbacks to handle
each result as it comes in.

The basic concept and some code was taken from the book "Python in a Nutshell"
by Alex Martelli, copyright 2003, ISBN 0-596-00188-6, from section 14.5
"Threaded Program Architecture". I wrapped the main program logic in the
ThreadPool class, added the WorkRequest class and the callback system and
tweaked the code here and there. Kudos also to Florent Aide for the exception
handling mechanism.

Basic usage:

>>> pool = TreadPool(poolsize)
>>> requests = makeRequests(some_callable, list_of_args, callback)
>>> [pool.putRequest(req) for req in requests]
>>> pool.wait()

See the end of the module code for a brief, annotated usage example.

Website : http://chrisarndt.de/en/software/python/threadpool/


Classes

class  NoResultsPending
class  NoWorkersAvailable
class  ThreadPool
class  WorkerThread
class  WorkRequest

Functions

def do_something
def handle_exception
def makeRequests
def print_result

Variables

list __all__
string __author__ = "Christopher Arndt"
string __date__ = "$Date: 2006/06/23 12:32:25 $"
string __license__ = 'Python license'
string __revision__ = "$Revision: 1.5 $"
string __version__ = "1.2.3"
list data = [random.randint(1,10) for i in range(20)]
int i = 0
tuple main = ThreadPool(3)
tuple requests = makeRequests(do_something, data, print_result, handle_exception)


Generated by  Doxygen 1.6.0   Back to index