threads or queue for this task

robin at robin at
Sat Sep 14 01:59:43 EDT 2002

I am missing something I think with the difference between the
threading and Queue modules. These could really do with some updated
docs with examples.

I wish to have a server continually cycle (until interrupted by
keyboard, signal, or whatever). It needs to perform several (say 6)
different tasks, each of which may take significantly different
lengths of time to perform.

My first implementation used I wrote a dispatcher to
start each of the threads, and then wait until the thread count was
back down to 1. This I put in a while loop, and surrounded it with the
necessary exception code.

Each cycle through the while has to wait for the slowest process to
finish before completing. During this time, the other processes just
sit around doing nothing. What I really want is for each process to
start up again when they are done, so that there are no more than 6
going at once. In other words, I want to be sure I don't start a new
process 3 before the old process 3 is done.

I have looked at Queue but it doesn't seem to have enough control to
make this happen.

I am sure I am overlooking something obvious. Thanks ahead of time for
any help!

-- robin

More information about the Python-list mailing list