Threadpool - Easy to use object-oriented thread pool framework

Friday, March 26, 2010

Threadpool

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 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 then possible to define callbacks to
handle each result as it comes in.

Basic usage

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

Installation

1, easy_install

sudo easy_install threadpool

2, or see the colorized source code:
threadpool.py

This entry was tagged Python

comments powered by Disqus

© 2009-2013 lxneng.com. All rights reserved. Powered by Pyramid

go to Top