471,108 Members | 1,321 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,108 software developers and data experts.

Re: Help on thread pool

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.
Jun 27 '08 #1
1 1002
On May 17, 2:23 pm, Jeff <jeffo...@gmail.comwrote:
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
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Meya-awe | last post: by
reply views Thread by roni schuetz | last post: by
1 post views Thread by richard.hallgren | last post: by
8 posts views Thread by =?Utf-8?B?cmFuZHkxMjAw?= | last post: by
3 posts views Thread by Venkat | last post: by
7 posts views Thread by Curious | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.