Reputation: 21914
In Python, what is the difference between using a thread.join
vs a queue.join
? I feel that it could both do the same job in some scenarios. Especially if there is a one-one correpodence between thread spawned and item picked from the queue for a job. Is it something like if you are going to use Threading
on a queue
, it is best to depend on queue.join
and if you are just doing something in paralelly where there is no queue
data structure used, but its something like a list
you could use thread.join
? Ofcourse in the scenario of thread.join
you need to mention all the threads spawned.
Also just as an aside is queue
something you would normally use for consuming input? I think in the scenario of chaining inputs for another job it makes sense to use as an output as well, but in general queue is for processing input? Can someone clarify?
Upvotes: 2
Views: 1264
Reputation: 9599
Queue.join
will wait for the queue to be empty (actually that Queue.task_done
is called for each item after processing). Thread.join
will block until all threads terminates. The behavior using one or other might be similar if all the threads take items from the queue, make a task and return when there's nothing left. However you can still have threads which don't use a queue at all, thus Queue.join
would be useless.
Upvotes: 2