Python Threads -

Alex Martelli aleax at
Thu Apr 19 06:09:12 CEST 2007

S.Mohideen <moin at> wrote:

> Hi All,
> Can you please suggest a technique in Python where we can spawn few number
> of worker threads and later map them to a function/s to execute individual
> Jobs.
> Any references would be helpful..

I believe I give some examples in the Nutshell, but the basic idea is
very simple: start the N worker threads you want in your pool -- they
all use .get on the same Queue.Queue instance qI which contains "work
requests" (WRs).  A WR could e.g. be a tuple with a Queue qO (or None to
indicate that the result is not interesting), a callable, and 0+
arguments (or an empty tuple to request thread termination); the worker
thread just calls the callable on the arguments and puts the result to
qO (if qO is not None).  Many other similar arrangements are possible,
depending on your application's exact needs, but I hope the general idea
is clear.


More information about the Python-list mailing list