<div class="gmail_quote">On Thu, May 6, 2010 at 12:14 PM, rosso rossi <span dir="ltr"><<a href="mailto:emilio84music@yahoo.it">emilio84music@yahoo.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit">Hello everybody,<br><br>I'm writing a small interface with python 2.6.5 and pyqt 4.7.3.<br><br>I'm testing this interface on windows, but i have the same problem in linux (windows and linux are 32-bit OS).<br>
<br>So... This is my problem:<br><br>In my interface i have 1 qpushbutton (self.Button) and 2 QLineEdit (Edit1, and edit2)<br><br>i connected qpushbutton with a funzion (pressbutton)<br><br>def pressbutton(self):<br> self.thread = threading.Thread( target=self.Thcall )<br>
self.thread.start()<br><br>def Thcall(self):<br> while(True): <br> self.t = Timer(10, self.Read) #10 seconds<br>
self.t.start()<br> self.t.join()<br><br>def Read(self):<br> Edit1.setText("a string")<br> Edit2.setText("another string")<br> #now here i have 500 linees of code, i read from serial port and compute these datas. It's take about 500ms<br>
Edit1.setText("finished")<br> Edit2.setText("finished")<br><br><br><br>as you can see my program is very simple (i omitted the first part, where i initialize Qwidget and move them in my window). But when my program enter in self.Read my windows freeze for some time (< 1 second). This is the first problem. Why it freeze?<br>
</td></tr></tbody></table></blockquote><div> </div><div><br></div><div>So, you omit 500 rules of code in which you listen to a serial port and need 500 milliseconds to calculate the received data.. My guess is that somewhere in those 500 lines of code, you call a method that's blocking the event loop of Qt. Probably a serialPort.read() invocation or so.. There is a way out though: you might want to look at QThread instead of using the python threading module. I'm not sure, but it doesn't secure the flow of the main event loop where QThread does so.</div>
<div> </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit">
Second problem: If i switch from antoher program (for example firefox) and my program, this crash....<br><br>Is there
some error in my code?<br></td></tr></tbody></table></blockquote><div><br></div><div>Well, I can say this isn't the fault of Firefox, nor python or PyQt. Maybe the cause can be found in the serial port listener? Again, you've omitted that part, so nobody can say for sure. </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit"><br>i want that when user push a button, my program will call function Read every 10 seconds FOREVER....<br>
<br>Thank you very much and sorry for my bad english<br><br></td></tr></tbody></table>
_______________________________________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></blockquote></div><br>-- <br>Nick Gaens<br>