[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>&nbsp;&nbsp; \
&nbsp;trigger = QtCore.pyqtSignal(FunctionType,list,dict)</div><div><br></div><div><div>&nbsp;&nbsp; \
&nbsp;def timer(self):</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;import \
time</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;print '1 sec'</div><div>&nbsp;&nbsp; \
&nbsp; &nbsp; &nbsp;reactor.callLater(1,self.timer)</div><div><br></div><div>&nbsp;&nbsp; \
&nbsp;def RCall(self,func,args,keys):</div><div>&nbsp;&nbsp; &nbsp; &nbsp; \
&nbsp;print 'good'</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;import \
time</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;time.sleep(5)</div><div>&nbsp;&nbsp; \
&nbsp; &nbsp; &nbsp;func(*args,**keys)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; \
&nbsp;</div><div>&nbsp;&nbsp; &nbsp;def run(self):</div><div>&nbsp;&nbsp; &nbsp; \
&nbsp; &nbsp;self.trigger.connect(self.RCall)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; \
&nbsp;self.MCall(mainWin.msgg)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; \
&nbsp;reactor.run(installSignalHandlers=0)</div><div><br></div><div>&nbsp;&nbsp; \
&nbsp;def MCall(self, fun, *args, **keys):</div><div>&nbsp;&nbsp; &nbsp; &nbsp; \
&nbsp;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>&nbsp;&nbsp; &nbsp;print \
'good'</div><div>&nbsp;&nbsp; &nbsp;import time</div><div>&nbsp;&nbsp; \
&nbsp;time.sleep(5)</div><div>&nbsp;&nbsp; \
&nbsp;func(*args,**keys)</div><div><br></div></div><div style="line-height: 21px; \
">class worker(QtCore.QThread):</div><div style="line-height: 21px; ">&nbsp;&nbsp; \
&nbsp;trigger = QtCore.pyqtSignal(FunctionType,list,dict)</div><div \
style="line-height: 21px; "><br></div><div style="line-height: 21px; "><div \
style="line-height: 21px; ">&nbsp;&nbsp; &nbsp;def timer(self):</div><div \
style="line-height: 21px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;import time</div><div \
style="line-height: 21px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;print '1 sec'</div><div \
style="line-height: 21px; ">&nbsp;&nbsp; &nbsp; &nbsp; \
&nbsp;reactor.callLater(1,self.timer)</div><div style="line-height: 21px; \
">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</div><div style="line-height: 21px; \
">&nbsp;&nbsp; &nbsp;def run(self):</div><div style="line-height: 21px; \
">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;self.trigger.connect(RCall)</div><div \
style="line-height: 21px; ">&nbsp;&nbsp; &nbsp; &nbsp; \
&nbsp;self.MCall(mainWin.msgg)</div><div style="line-height: 21px; ">&nbsp;&nbsp; \
&nbsp; &nbsp; &nbsp;reactor.run(installSignalHandlers=0)</div><div \
style="line-height: 21px; "><br></div><div style="line-height: 21px; ">&nbsp;&nbsp; \
&nbsp;def MCall(self, fun, *args, **keys):</div><div style="line-height: 21px; \
">&nbsp;&nbsp; &nbsp; &nbsp; \
&nbsp;self.trigger.emit(fun,args,keys)</div><div><br></div><div>the version DON'T \
WORK... &nbsp;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; ">&nbsp;&nbsp; &nbsp;print \
'good'</div><div style="line-height: 21px; ">&nbsp;&nbsp; &nbsp;import time</div><div \
style="line-height: 21px; ">&nbsp;&nbsp; &nbsp;time.sleep(5)</div><div \
style="line-height: 21px; ">&nbsp;&nbsp; &nbsp;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; ">&nbsp;&nbsp; \
&nbsp;trigger = QtCore.pyqtSignal(FunctionType,list,dict)</div><div \
style="line-height: 21px; "><br></div><div style="line-height: 21px; "><div \
style="line-height: 21px; ">&nbsp;&nbsp; &nbsp;def timer(self):</div><div \
style="line-height: 21px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;import time</div><div \
style="line-height: 21px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;print '1 sec'</div><div \
style="line-height: 21px; ">&nbsp;&nbsp; &nbsp; &nbsp; \
&nbsp;reactor.callLater(1,self.timer)</div><div style="line-height: 21px; \
">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</div><div style="line-height: 21px; \
">&nbsp;&nbsp; &nbsp;def run(self):</div><div style="line-height: 21px; \
">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;self.MCall(mainWin.msgg)</div><div \
style="line-height: 21px; ">&nbsp;&nbsp; &nbsp; &nbsp; \
&nbsp;reactor.run(installSignalHandlers=0)</div><div style="line-height: 21px; \
"><br></div><div style="line-height: 21px; ">&nbsp;&nbsp; &nbsp;def MCall(self, fun, \
*args, **keys):</div><div style="line-height: 21px; ">&nbsp;&nbsp; &nbsp; &nbsp; \
&nbsp;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