Too many threads

Cameron Simpson cs at
Fri Sep 17 06:38:26 CEST 2010

On 16Sep2010 09:55, mark.pelletier at <mark.pelletier at> wrote:
| For some reason, the tasks I put into my thread pool occasionally get
| run more than once.
| Here's the code:

You need to post your _exact_ code. I had to change:
  from queue import Queue
  from Queue import Queue
So: _do_ you have a "queue" (lowercase) module? Is it buggy?

Let's pretend not.

Using the standard Queue module I can't reproduce your problem and your
code looks correct to my eye.

However, it is possible that the output stream used by print() is not
thread safe. In which case your multiple outputs may stem from output
buffer mishandling and not from your thread pool.

Make another Queue to receice items, change _worker() to .put(item) onto
it and collect form the queue and print in the program's main code. That
way only one thread (the main one) will be trying to print(), removing the
possibility of mismanagement of the output if print() is not thread safe.

Cameron Simpson <cs at> DoD#743

Rules of Optimization:
Rule 1: Don't do it.
Rule 2 (for experts only): Don't do it yet.
- M.A. Jackson

More information about the Python-list mailing list