Hi,<br>That is a bit odd. Are you using the latest version of SIP and PyQt?. When I'm running the example I posted to you without the Qt.QueuedConnection parameter i get the following output:<br><br>0 starting<br>0 Creating thread
<br>3 finished in b()<br>3 finished in __main__ <br><br>The worker thread is locking the GUI thread. When I use the Qt.QueuedConnection parameter in the connect call i get the following ouput:<br><br>0 starting<br>0 Creating thread
<br>0 finished in __main__<br>3 finished in b()<br><br>As you can see the worker thread is not blocking the GUI thread.<br><br>Regards,<br>Ole<br><br><br><br><div><span class="gmail_quote">On 1/8/07, <b class="gmail_sendername">
Paul Giannaros</b> <<a href="mailto:ceruleanblaze@gmail.com">ceruleanblaze@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
No such luck. I think I mentioned in the source code I tried that. See the<br>given example:<br><br>from PyQt4.QtGui import *<br>from PyQt4.QtCore import *<br><br>import sys<br>from time import time<br><br>class B (QThread):
<br> def __init__(self):<br> QThread.__init__(self)<br> p("Creating thread")<br><br> def bfunc(self):<br> self.sleep(3)<br> p("finished in b()")<br><br> def run(self):
<br> self.exec_()<br><br><br>class A(QDialog):<br> def __init__(self):<br> QDialog.__init__(self, None)<br> self.l = QLabel("Foo bar baz", self)<br> #layout = QVBoxLayout(self)<br>
#layout.addWidget(self.l)<br> #self.l.move(0, 0)<br> self.resize(200, 100)<br> self.move(100, 100)<br> self.b = b = B()<br> b.start()<br> QObject.connect(self, SIGNAL("asignal"),
b.bfunc, Qt.QueuedConnection)<br> QTimer.singleShot(1000, self.afunc)<br><br> def afunc (self):<br> self.emit(SIGNAL("asignal"))<br><br><br>def p(msg):<br> print int(time() - start), msg<br><br>
if __name__ == "__main__":<br> start = time()<br> p("starting")<br> app = QApplication(sys.argv)<br> a = A()<br> a.show()<br> #a.afunc()<br> p("finished in __main__")<br>
sys.exit(app.exec_())<br><br><br><br>I have discovered, however, that regular Python threads work fine if I use a<br>data-based/mutex model. I think i'll go with that for now.<br><br><br>On Monday 08 January 2007 13:25, Ole Morten Grodås wrote:
<br>> Hi,<br>><br>> Try using Qt.QueuedConnection. I think that is your problem. Her is an<br>> example:<br>><br>> import sys<br>> from time import time<br>> from PyQt4.QtCore import *<br>><br>> class B (QThread):
<br>> def __init__(self):<br>> QThread.__init__(self)<br>> p("Creating thread")<br>><br>> def bfunc(self):<br>> self.sleep(3)<br>> p("finished in b()")
<br>><br>> def run(self):<br>> self.exec_()<br>><br>> class A (QObject):<br>> def __init__(self):<br>> QObject.__init__(self)<br>><br>> def afunc (self):<br>>
self.emit(SIGNAL("asignal"))<br>><br>><br>> def p(msg): print int(time()-start),msg<br>> if __name__=="__main__":<br>> start=time()<br>> p("starting")<br>> app=QCoreApplication(
sys.argv)<br>> a=A()<br>> b=B()<br>> b.start()<br>> QObject.connect(a,SIGNAL("asignal"),b.bfunc,Qt.QueuedConnection)<br>> a.afunc()<br>> p("finished in __main__")
<br>><br>> sys.exit(app.exec_())<br>><br>><br>> The example gives this output<br>> 0 starting<br>> 0 Creating thread<br>> 0 finished in __main__<br>> 3 finished in b()<br>><br>><br>>
<br>> Regards,<br>> Ole Morten Grodås<br>><br>> On 1/7/07, Paul Giannaros <<a href="mailto:ceruleanblaze@gmail.com">ceruleanblaze@gmail.com</a>> wrote:<br>> > I've been trying to get the main GUI thread to pass a URL to a worker
<br>> > thread<br>> > and have it download that (without the GUI thread blocking). I haven't<br>> > been<br>> > able to do it successfully, i've tried all manner of connects/postEvents.<br>
> > Here is a simplified example:<br>> ><br>> > <a href="http://rafb.net/p/etOoSH97.html">http://rafb.net/p/etOoSH97.html</a><br>> ><br>> > In the example i'm trying to get the main thread to cause the MyThread
<br>> > instance to sleep without blocking the main thread. In MyThread.run I<br>> > call MyThread.foo (which blocks for 5 seconds) without a problem - the<br>> > GUI thread<br>> > isn't being blocked. When I try to get the main thread to indirectly
<br>> > invoke<br>> > foo (via emitting a signal that the thread listens for, or by posting an<br>> > event that MyThread picks up in customEvent), then the GUI thread blocks.<br>> ><br>> > It's quite crippling. What's the correct way to go about this?
<br>> ><br>> > Thanks,<br>> > Paul<br>> ><br>> > _______________________________________________<br>> > PyKDE mailing list <a href="mailto:PyKDE@mats.imk.fraunhofer.de">PyKDE@mats.imk.fraunhofer.de
</a><br>> > <a href="http://mats.imk.fraunhofer.de/mailman/listinfo/pykde">http://mats.imk.fraunhofer.de/mailman/listinfo/pykde</a><br><br>_______________________________________________<br>PyKDE mailing list <a href="mailto:PyKDE@mats.imk.fraunhofer.de">
PyKDE@mats.imk.fraunhofer.de</a><br><a href="http://mats.imk.fraunhofer.de/mailman/listinfo/pykde">http://mats.imk.fraunhofer.de/mailman/listinfo/pykde</a><br></blockquote></div><br>