[英]Python queues - number of task_done()
I wish to know the amount of tasks completed (the sum completed by all threads) for a queue in a multi-threaded program. 我希望知道多线程程序中队列的已完成任务数量(所有线程已完成的总和)。 What is the best way to find this out? 找出答案的最佳方法是什么? I note that: 我注意到:
You could try extending the Queue class. 您可以尝试扩展Queue类。 Something like 就像是
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.