Help on thread pool
Alex
metallourlante at gmail.com
Sat May 17 10:03:27 EDT 2008
On May 17, 2:23 pm, Jeff <jeffo... at gmail.com> wrote:
> Your worker threads wait around forever because there is no place for
> them to exit. Queue.get() by default blocks until there is an item in
> the queue available. You can do something like this to cause the
> worker to quit when the queue is empty. Just make sure that you fill
> the queue before starting the worker threads.
>
> from Queue import Queue, Empty
>
> # in your worker
> while True:
> try:
> item = q.get(block=False)
> except Empty:
> break
> do_something_with_item()
> q.task_done()
>
> You can also use a condition variable and a lock or a semaphore to
> signal the worker threads that all work has completed.
Thanks a lot, it works!
Alex
More information about the Python-list
mailing list