Re: Help on thread pool

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff

    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=Fal se)
    except Empty:
    break
    do_something_wi th_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.
  • Alex

    #2
    Re: Help on thread pool

    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=Fal se)
    except Empty:
    break
    do_something_wi th_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

    Comment

    Working...