On 3/14/06, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > FWIW, I've been working on a way to simplify the use of queues with daemon > consumer threads > > Sometimes, I launch one or more consumer threads that wait for a task to > enter a > queue and then work on the task. A recurring problem is that I sometimes need > to > know if all of the tasks have been completed so I can exit or do something > with > the result. [...] > So, the idea is to create a subclass of Queue that increments a counter when > objects are enqueued, that provides a method for worker threads to decrement > the > counter when the work is done, and offers a blocking join() method that waits > until the counter is zero
I've also hit this problem, and would find this pattern useful. FWIW, in my code, I bypassed the problem by spawning one worker per task, and waiting on them all. This works, but is sub-optimal (there's no need for 100+ subthreads, when 20 or so generic workers would have done...) Paul. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com