[PyQt] Fwd: Re: Main UI stuck when ping sub thread running

Florian Bruhin me at the-compiler.org
Thu Jun 26 05:08:16 BST 2014


Just noticed I didn't send this to the list yesterday. Here it is, for
the sake of completeness :)

----- Forwarded message from Florian Bruhin <me at the-compiler.org> -----

Date: Wed, 25 Jun 2014 14:36:47 +0200
From: Florian Bruhin <me at the-compiler.org>
To: 不坏阿峰 <onlydebian at gmail.com>
Subject: Re: [PyQt] Main UI stuck when ping sub thread running

* 不坏阿峰 <onlydebian at gmail.com> [2014-06-23 20:05:51 +0700]:
> 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
>
> [...]
> 
>     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)

Here you block until the thread is finished and then even sleep some
more - that's roughly equivalent to not using threads at all, right?

I'd instead use QThreads, and then you can use a signal in the thread
when you got your ping result, and bind a slot to that signal.

I do something similiar here:
http://git.the-compiler.org/qutebrowser/tree/qutebrowser/commands/userscripts.py

_BlockingFifoReader is my worker which does do something that blocks
(self.read for me), and emits a got_line signal.

_POSIXUserscriptRunner creates a new QThread, moves the worker to the
thread, connects the signals and starts it.

You probably want to do something similiar, with ping instead of I/O,
and minus the QProcess stuff.

Florian

----- End forwarded message -----

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
             GPG 0xFD55A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140626/3c026a45/attachment.sig>


More information about the PyQt mailing list