<HTML>
<HEAD>
<TITLE>Re: [PyQt] Avoiding freeze of the application</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>If you don’t want to use QProcess, you can use subprocess.Popen and the poll() method.<BR>
<BR>
This would be something like:<BR>
<BR>
popen = Subprocess.Popen("plink -batch %s@%s echo" %<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'> (self.beqLineEdit.text(), self.linuxmachineComboBox.currentText())<BR>
, shell=True<BR>
, stderr=errptr)<BR>
<BR>
</SPAN></FONT></BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>And in some QTimer bound method:<BR>
<BR>
retcode = popen.poll()<BR>
if retcode is not None:<BR>
# process has finished<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT></BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>QProcess is nice because it already has a signal that it sends when the process terminates. subprocess.Popen also has some quirks like you can’t use poll.wait or os.wait and popen.poll at the same time.<BR>
<BR>
Brian<BR>
<BR>
<BR>
On 2/7/09 11:00 AM, "Phil Thompson" <<a href="phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>On Sat, 07 Feb 2009 16:53:27 +0100, Geert Vancompernolle<BR>
<<a href="geert.discussions@gmail.com">geert.discussions@gmail.com</a>> wrote:<BR>
> Hi,<BR>
><BR>
> I want to achieve the following:<BR>
><BR>
> * My (Windows) application is trying to make a connection with a Linux<BR>
> server, using another application (plink, part of the Putty distro)<BR>
> * Since an external application is to be called, I'm using the method<BR>
> subprocess in this way:<BR>
> retcode = subprocess.call( "plink -batch %s@%s echo" %<BR>
> (self.beqLineEdit.text(), self.linuxmachineComboBox.currentText())<BR>
> , shell=True<BR>
> , stderr=errptr<BR>
> )<BR>
> * However, that call can take up to 10 seconds (worst case). In the<BR>
> mean time, my main application is "frozen", I can't do anything else.<BR>
><BR>
> Now, what I would like to do, is to decouple the above call from the<BR>
> main thread, such that the main application becomes "free" again. I<BR>
> also would like to start a one shot timer (using QTimer.singleShot()) to<BR>
> create a time-out. This is to prevent a "hang" of the application, in<BR>
> case something goes wrong during the subprocess call.<BR>
><BR>
> So, my intention is to check when the one shot timer elapses, if the<BR>
> subprocess call is still busy. If not, then all is fine and I simply<BR>
> ignore the time out. If the subprocess is still busy, I would like to<BR>
> be able to (if needed, forcefully) stop the subprocess call.<BR>
><BR>
> I currently started the one shot timer just before I launched the<BR>
> subprocess call, but I see that the one shot timer is also blocked by<BR>
> the subprocess call. So, that doesn't do what I in fact want to do.<BR>
><BR>
> My questions:<BR>
><BR>
> 1. How can I "decouple" the subprocess call?<BR>
> 2. How can I forcefully stop a subprocess call (that should be the case<BR>
> if my one shot timer elapses after 10 seconds, and the subprocess call<BR>
> is not returned yet)?<BR>
> 3. What's the best approach to achieve the above requirements? Using a<BR>
> kind of a state machine, where I first start the subprocess call<BR>
> (decoupled), then start the one shot timer, change the state and then<BR>
> check in that state if the subprocess call has indeed ended? And if<BR>
> not, forcefully stop the subprocess call?<BR>
><BR>
> Any practical helpful tips much appreciated!<BR>
<BR>
Use QProcess instead of subprocess.<BR>
<BR>
Phil<BR>
_______________________________________________<BR>
PyQt mailing list <a href="PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><BR>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><BR>
<BR>
</SPAN></FONT></BLOCKQUOTE>
</BODY>
</HTML>