I wrote a script that has multiple threads (created with threading.Thread
) fetching URLs from a Queue
using queue.get_nowait()
, and then processing the HTML. I am new to multi-threaded programming, and am having trouble understanding the purpose of the queue.task_done()
function.
When the Queue
is empty, it automatically returns the queue.Empty
exception. So I don't understand the need for each thread to call the task_done()
function. We know that we're done with the queue when its empty, so why do we need to notify it that the worker threads have finished their work (which has nothing to do with the queue, after they've gotten the URL from it)?
Could someone provide me with a code example (ideally using urllib
, file I/O, or something other than fibonacci numbers and printing "Hello") that shows me how this function would be used in practical applications?