Producer-consumer threading problem

George Sakkis george.sakkis at gmail.com
Wed Jun 11 14:00:13 CEST 2008


On Jun 11, 1:59 am, Rhamphoryncus <rha... at gmail.com> wrote:

> Why not use a normal Queue, put a dummy value (such as None) in when
> you're producer has finished, and have the main thread use the normal
> Thread.join() method on all your child threads?

I just gave two reasons:
- Concurrency / interactivity. The main thread shouldn't wait for all
one million items to be produced to get to see even one of them.
- Limiting resources. Just like iterating over the lines of a file is
more memory efficient than reading the whole file in memory, getting
each consumed item as it becomes available is more memory efficient
than waiting for all of them to finish.

George



More information about the Python-list mailing list