[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] problem of pyqtSignal in multi threads
From: "=?ISO-8859-1?B?TGlvbg==?=" <lionweb () qq ! com>
Date: 2010-05-28 1:34:43
Message-ID: tencent_0D6379AA20A271F13EA0A3C2 () qq ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
[Attachment #4 (text/plain)]
version 1:
class worker(QtCore.QThread):
trigger = QtCore.pyqtSignal(FunctionType,list,dict)
def timer(self):
import time
print '1 sec'
reactor.callLater(1,self.timer)
def RCall(self,func,args,keys):
print 'good'
import time
time.sleep(5)
func(*args,**keys)
def run(self):
self.trigger.connect(self.RCall)
self.MCall(mainWin.msgg)
reactor.run(installSignalHandlers=0)
def MCall(self, fun, *args, **keys):
self.trigger.emit(fun,args,keys)
the version works , but what i confused is that the signal block the mainthread \
rather than the new thread.
version 2:
def RCall(func,args,keys):
print 'good'
import time
time.sleep(5)
func(*args,**keys)
class worker(QtCore.QThread):
trigger = QtCore.pyqtSignal(FunctionType,list,dict)
def timer(self):
import time
print '1 sec'
reactor.callLater(1,self.timer)
def run(self):
self.trigger.connect(RCall)
self.MCall(mainWin.msgg)
reactor.run(installSignalHandlers=0)
def MCall(self, fun, *args, **keys):
self.trigger.emit(fun,args,keys)
the version DON'T WORK... without any error, but the slot never triggered
version 3:
def RCall(func,args,keys):
print 'good'
import time
time.sleep(5)
func(*args,**keys)
class worker(QtCore.QThread):
trigger = QtCore.pyqtSignal(FunctionType,list,dict)
def timer(self):
import time
print '1 sec'
reactor.callLater(1,self.timer)
def run(self):
self.MCall(mainWin.msgg)
reactor.run(installSignalHandlers=0)
def MCall(self, fun, *args, **keys):
self.trigger.emit(fun,args,keys)
thread = worker()
thread.trigger.connect(RCall)
this version work perfectly.
now , What trouble me most is who will be the receiver of pyqtSignal exactly???
[Attachment #5 (text/html)]
<div>version 1:</div><div>class worker(QtCore.QThread):</div><div> \
trigger = QtCore.pyqtSignal(FunctionType,list,dict)</div><div><br></div><div><div> \
def timer(self):</div><div> import \
time</div><div> print '1 sec'</div><div> \
reactor.callLater(1,self.timer)</div><div><br></div><div> \
def RCall(self,func,args,keys):</div><div> \
print 'good'</div><div> import \
time</div><div> time.sleep(5)</div><div> \
func(*args,**keys)</div><div> \
</div><div> def run(self):</div><div> \
self.trigger.connect(self.RCall)</div><div> \
self.MCall(mainWin.msgg)</div><div> \
reactor.run(installSignalHandlers=0)</div><div><br></div><div> \
def MCall(self, fun, *args, **keys):</div><div> \
self.trigger.emit(fun,args,keys)</div></div><div><br></div><div>the version \
works , but what i confused is that the signal block the mainthread rather than the \
new thread.</div><div><br></div><div>version 2:</div><div><div style="line-height: \
21px; "><br></div><div style="line-height: 21px; "><div>def \
RCall(func,args,keys):</div><div> print \
'good'</div><div> import time</div><div> \
time.sleep(5)</div><div> \
func(*args,**keys)</div><div><br></div></div><div style="line-height: 21px; \
">class worker(QtCore.QThread):</div><div style="line-height: 21px; "> \
trigger = QtCore.pyqtSignal(FunctionType,list,dict)</div><div \
style="line-height: 21px; "><br></div><div style="line-height: 21px; "><div \
style="line-height: 21px; "> def timer(self):</div><div \
style="line-height: 21px; "> import time</div><div \
style="line-height: 21px; "> print '1 sec'</div><div \
style="line-height: 21px; "> \
reactor.callLater(1,self.timer)</div><div style="line-height: 21px; \
"> </div><div style="line-height: 21px; \
"> def run(self):</div><div style="line-height: 21px; \
"> self.trigger.connect(RCall)</div><div \
style="line-height: 21px; "> \
self.MCall(mainWin.msgg)</div><div style="line-height: 21px; "> \
reactor.run(installSignalHandlers=0)</div><div \
style="line-height: 21px; "><br></div><div style="line-height: 21px; "> \
def MCall(self, fun, *args, **keys):</div><div style="line-height: 21px; \
"> \
self.trigger.emit(fun,args,keys)</div><div><br></div><div>the version DON'T \
WORK... without any error, but the slot never \
triggered</div><div><br></div><div>version 3:</div><div><br></div><div><div \
style="line-height: 21px; "><div style="line-height: 21px; ">def \
RCall(func,args,keys):</div><div style="line-height: 21px; "> print \
'good'</div><div style="line-height: 21px; "> import time</div><div \
style="line-height: 21px; "> time.sleep(5)</div><div \
style="line-height: 21px; "> func(*args,**keys)</div><div \
style="line-height: 21px; "><br></div></div><div style="line-height: 21px; ">class \
worker(QtCore.QThread):</div><div style="line-height: 21px; "> \
trigger = QtCore.pyqtSignal(FunctionType,list,dict)</div><div \
style="line-height: 21px; "><br></div><div style="line-height: 21px; "><div \
style="line-height: 21px; "> def timer(self):</div><div \
style="line-height: 21px; "> import time</div><div \
style="line-height: 21px; "> print '1 sec'</div><div \
style="line-height: 21px; "> \
reactor.callLater(1,self.timer)</div><div style="line-height: 21px; \
"> </div><div style="line-height: 21px; \
"> def run(self):</div><div style="line-height: 21px; \
"> self.MCall(mainWin.msgg)</div><div \
style="line-height: 21px; "> \
reactor.run(installSignalHandlers=0)</div><div style="line-height: 21px; \
"><br></div><div style="line-height: 21px; "> def MCall(self, fun, \
*args, **keys):</div><div style="line-height: 21px; "> \
self.trigger.emit(fun,args,keys)</div></div></div><div><br></div><div>thread = \
worker()</div><div>thread.trigger.connect(RCall)</div><div><br></div><div>this \
version work perfectly.</div><div><br></div><div>now , What trouble me most is who \
will be the receiver of pyqtSignal exactly???</div></div></div>
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic