另外请问一下使用
queue.join()
queue.task_done()
和
while not workQueue.empty():
pass
这两种方式来判断队列中是否还有任务的机制有区别吗?哪种更好呢?
怪我咯2017-04-18 09:59:50
It depends on your design and usage scenarios.
queue.join will block until all messages in the queue are retrieved and task_done is called before returning. Usually used to wait for all tasks to be processed and then exit the process.
Empty will return immediately. When checking with your while loop, if the queue is empty, the thread will continue to loop endlessly. Waiting in a loop consumes a lot of CPU.