task_done() 在做什么?
laixintao opened this issue · 2 comments
laixintao commented
P109
A queue has the JoinaleQueue subclass. It has the following two additional methods:
f task_done(): This indicates that a task is complete, for example, after the get() method is used to fetch items from the queue. So, it must be used only by queue consumers.
这里的介绍和官网文档一样,不是很懂。
Microndgt commented
因为使用队列进行通信是一个单向的,不确定的过程,所以你不知道什么时候队列的元素被取出来了,所以使用task_done来表示已经队列里的一个任务已经完成。
这个方法一般和join一起使用,当队列的所有任务都处理之后,也就是说put到队列的每个任务都调用了task_done方法后,join才会完成阻塞。