Good thread pool module

Raymond Hettinger python at rcn.com
Thu Mar 23 00:35:28 EST 2006


David Hirschfield wrote:
> There isn't a thread pool module in the standard library, but I'm sure
> many have been written by people in the python community.
> Anyone have a favorite? Is there one particular implementation that's
> recommended?

Because of the GIL, thread pools are not as useful in Python as you
might expect -- they execute one at a time and do not take advantage of
hyper-threading or multiple processors.  If that kind of efficiency is
what you are after, then take a look at PyLinda which can coordinate
communication between multiple instances of Python running in separate
threads:

    http://www-users.cs.york.ac.uk/~aw/pylinda/

> Not looking for anything fancy, just something that lets me queue up
> tasks to be performed by a pool of threads and then retrieve results
> when the tasks complete.

FWIW, I wrote a small enchancement to the Queue module that makes it a
little bit easier to use a pool of worker threads and then be able to
tell when they are all done with processing:

   http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475160


Raymond




More information about the Python-list mailing list