java - python中queue的task_done和join起什么作用?
PHPz
PHPz 2017-04-18 09:57:50
0
1
860

另外请问一下使用

queue.join()
queue.task_done()

while not workQueue.empty():
    pass

这两种方式来判断队列中是否还有任务的机制有区别吗?哪种更好呢?

PHPz
PHPz

学习是最好的投资!

reply all(1)
刘奇

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!