Too many threads
Cameron Simpson
cs at zip.com.au
Fri Sep 17 00:38:26 EDT 2010
On 16Sep2010 09:55, mark.pelletier at asrcms.com <mark.pelletier at asrcms.com> 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
into
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.
Cheers,
--
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/
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