[PyQt] Main UI stuck when ping sub thread running

Glenn Ramsey gr at componic.co.nz
Wed Jun 25 22:17:54 BST 2014


Hi,

It looks like your main thread waits because you are calling join() on the 
worker thread. I suggest you look up the docs for thread.join to see what that does.

Glenn

On 25/06/14 04:51, 不坏阿峰 wrote:
> any person can help?
>
>
> 2014-06-23 20:05 GMT+07:00 不坏阿峰 <onlydebian at gmail.com
> <mailto:onlydebian at gmail.com>>:
>
>     i want to make a tools to diagnosis network. but my Main UI will stuck when
>     ping is running before finish.  All i want is that when the sub thread is
>     running, Main UI can use and go to other tab and can do other function.
>
>     pls help me . many thanks
>
>     ###########
>     from mychart_ui import Ui_Form
>     import verbose_ping01
>     import threading
>
>     class MyThread(threading.Thread):
>          def __init__(self, func, args, name=''):
>              threading.Thread.__init__(self)
>     self.name <http://self.name> = name
>              self.func = func
>              self.args = args
>
>          def run(self):
>              self.res = apply(self.func, self.args)
>
>          def getRes(self):
>              return self.res
>     def myping(host):
>          result = verbose_ping01.verbose_ping(host, count=500)
>          return result
>
>     class myWidget(QtGui.QWidget, Ui_Form):
>          def __init__(self,parent=None):
>              QtGui.QWidget.__init__(self, parent)
>              self.setupUi(self)
>              self.pushButton.clicked.connect(self.draw)
>              self.pushButton_ping.clicked.connect(self.doping)
>
>          def draw(self):
>              print  '='
>              sc = MyStaticMplCanvas(self.matwidget, width=2, height=3, dpi=100)
>              sc.show()
>          def doping(self):
>              thisthread = MyThread(myping,("192.168.123.50",))
>              thisthread.start()
>              thisthread.join()
>              time.sleep(0.5)
>              self.pingresult = thisthread.getRes()
>              newtext = "\n".join(self.pingresult)
>              self.pTE_pingresult.setPlainText(newtext)
>
>     qApp = QtGui.QApplication(sys.argv)
>     aw = myWidget()
>     aw.show()
>     sys.exit(qApp.exec_())
>



More information about the PyQt mailing list