[PyQt] moveToThread() does not cope with functools.partial

Giuseppe Corbelli giuseppe.corbelli at copanitalia.com
Tue Apr 23 09:08:23 BST 2013


Please see the minimal test code below. In short connecting a signal to a 
functools.partial slot breaks the expected moveToThread behaviour.
Reasonable, I'd say, once you think about it. I'm just asking some suggestion 
about how this issue can be addressed. I thought about reimplementing some 
signal class with a connect_partial method that stores bound args.
Python 2.7.3, Qt 4.8.2, PyQt 4.10 on Linux.


#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import functools

from PyQt4 import QtCore

class CApp(QtCore.QCoreApplication):
     mysignal = QtCore.pyqtSignal()

class CA(QtCore.QObject):
     def standard_slot(self):
         print "standard_slot", QtCore.QThread.currentThreadId()

     def partial_slot(self, param):
         print "partial_slot", param, QtCore.QThread.currentThreadId()

app = CApp(sys.argv)
print "CApp", QtCore.QThread.currentThreadId()

thread = QtCore.QThread()

a = CA()
a.moveToThread(thread)
thread.start()
while not thread.isRunning():
     pass

app.mysignal.connect(a.standard_slot, QtCore.Qt.QueuedConnection)
app.mysignal.connect(functools.partial(a.partial_slot, "aParam"), 
QtCore.Qt.QueuedConnection)

timer = QtCore.QTimer()
timer.setInterval(1000)
timer.timeout.connect(app.mysignal.emit)
timer.start()

app.exec_()


-- 
             Giuseppe Corbelli
WASP Software Engineer, Copan Italia S.p.A
Phone: +390303666318  Fax: +390302659932
E-mail: giuseppe.corbelli at copanitalia.com


More information about the PyQt mailing list