如何在获取数据时阻止我的pyqt程序冻结?

时间:2017-03-12 19:21:30

标签: python qthread

我的程序使用" speedtest"测试我的网速。我从pypi下载的模块。它按预期工作,但面临的问题是GUI冻结,直到收集完所有内容并显示它而不是逐个显示结果。这是我的程序代码

from PyQt4 import QtGui
from PyQt4. QtCore import SIGNAL
import Speed2
import sys
import speedtest

class Speed(QtGui.QDialog, Speed2.Ui_Dialog):
    def __init__(self):
        QtGui.QDialog.__init__(self)
        self.setupUi(self)

        self.waitingSlot.setText('Testing your internet speed......................')

        try:
            speed = speedtest.Speedtest()
            details = speed.config
            self.providerSlot.setText('%(isp)s ' %details ['client'])
            #server
            self.waitingSlot.setText('Selecting best server based on ping......................')
            speed.get_best_server()
            #host
            host =  speed.get_best_server()
            self.serverSlot.setText('%(sponsor)s (%(name)s) [%(d)0.2f km] '%host)
            #ping
            self.pingSpeed.setText('%(latency)d' % host)
            #download
            self.waitingSlot.setText('Testing your download speed')
            download  = speed.download()
            down  = (download / 1000.0 /1000.0)
            if down > 99:
                downlink  = round(down, 1)
                self.downLink.setText(str(downlink))
            else:
                downlink = round(down, 2)
                self.downLoad.setText(str(downlink))
            #upload
            self.waitingSlot.setText('Testing your upload speed......................')
            upload = speed.upload()
            up  = (upload / 1000.0/ 1000.0)
            if up > 99:
                uplink = round(up, 1)
                sellf.upLoad.setText(str(uplink))
            else:
                uplink = round(up, 2)
                self.upLoad.setText(str(uplink))            
            self.waitingSlot.setText('Testing complete!!!!')

        except:
            self.waitingSlot.setText('Error in network connection') 


def main():
    app = QtGui.QApplication(sys.argv)
    gui = Speed()
    gui.show()
    app.exec_()

if __name__ == '__main__':
    main()

0 个答案:

没有答案