如何知道每个线程的进度?
我是Python新手,我创建了一个具有多线程的上传程序,我的问题是我只有一个进度条来显示每个线程的进度。 我使用 python pyqt4 QThread。 有没有办法知道每个上传线程的进度? 这是代码的一些部分。
class Worker(QThread):
def __init__(self,parent=None):
QThread.__init__(self,parent)
self.counter = 0
self.received = 0
self.size = 0
self.f = None
self.ftp = None
self.filename = ""
def __del__(self):
self.wait()
def handleDownload(self, block):
self.counter += 1
self.received += len(block)
然后,handleDownload() 将向进度条发出信号以更新其值。
谢谢
im new in python and i have created an uploading program with multi threading, my problem is i have only one progress bar that displays the progress of each thread.
im using python pyqt4 QThread.
Is there a way to know whats the progress of each uploading thread?
here are some parts of the code.
class Worker(QThread):
def __init__(self,parent=None):
QThread.__init__(self,parent)
self.counter = 0
self.received = 0
self.size = 0
self.f = None
self.ftp = None
self.filename = ""
def __del__(self):
self.wait()
def handleDownload(self, block):
self.counter += 1
self.received += len(block)
the handleDownload() will then emit signal to the progress bar to update its value.
thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建一个在所有线程之间共享的计数器对象。每次线程完成下载时,它都会使用 QMutex 增加计数并解锁,然后您可以发送信号并修改进度条(尽管您可能想确保它不会更新得太频繁)
You need to create a counter object that's shared between all threads. Each time a thread completes a download it locks with a QMutex increments the count and unlocks you can then send your signal and modify the progress bar(although you may want to make sure it doesn't update too often)