Python队列-已完成的任务数()
我想知道多线程程序中队列完成的任务量(所有线程完成的总数)。最好的办法是什么? 我注意到:Python队列-已完成的任务数(),python,multithreading,python-3.x,queue,Python,Multithreading,Python 3.x,Queue,我想知道多线程程序中队列完成的任务量(所有线程完成的总数)。最好的办法是什么? 我注意到: 我已经阅读了文档,似乎没有一个简单的方法() queue类的“join”方法表明这是可以完成的,因为这是指调用task_done()方法 “qsize”方法返回队列中当前未处理的项目数(据我所知),即与task_done()没有关系 最好使用Python3.4解决方案 您可以尝试扩展队列类。差不多 from queue import Queue class MyQueue(Queue): de
您可以尝试扩展队列类。差不多
from queue import Queue
class MyQueue(Queue):
def __init__(self):
#In py3, I believe you can just use super()
#with no args
super(MyQueue, self).__init__()
self.completed_count = 0
def task_done(self):
self.completed_count += 1
super(MyQueue, self).task_done()
def get_task_count(self):
return self.completed_count