Gracias por vuestras respuestas!! Estoy intentando entender el tema de las señales desde los threads, pero el problema que estoy teniendo es que al enviar un parametro desde el "main" a uno de los threads para que haga algo con el no funciona, no se si esto es posible, de momento lo que he hecho es esto, por si sirve de ayuda:
Código Python:
Ver originalimport sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import time
class MyThread(QThread):
def __init__(self, name):
super(MyThread, self).__init__()
self.setObjectName(name)
def run(self):
print "RUN", QThread.currentThread().objectName(), QApplication.instance().thread().objectName()
self.exec_()
print "RUN DONE", QThread.currentThread().objectName()
class Producer(QObject):
def __init__(self, parent=None):
super(Producer, self).__init__(parent)
def Start(self,vector):
for i in vector:
if i == 1:
self.emit(SIGNAL("testsignal"),1)
time.sleep(2)
else:
self.emit(SIGNAL("testsignal"),0)
time.sleep(2)
time.sleep(1)
qApp.quit()
class Consumer(QObject):
def __init__(self, parent=None):
super(Consumer, self).__init__(parent)
def Consume(self, i):
print "Value = ",i
if __name__ == "__main__":
vector = [0,1,0,1,1,0,0,1,0]
app = QApplication([])
producer = Producer()
consumer = Consumer()
QThread.currentThread().setObjectName("MAIN")
producerThread = MyThread("producer")
consumerThread = MyThread("consumer")
producer.moveToThread(producerThread)
consumer.moveToThread(consumerThread)
producerThread.started.connect(producer.Start(vector))
producer.connect(producer, SIGNAL("testsignal"), consumer.Consume)
def aboutToQuit():
producerThread.quit()
consumerThread.quit()
time.sleep(1)
qApp.aboutToQuit.connect(aboutToQuit)
consumerThread.start()
time.sleep(.1)
producerThread.start()
sys.exit(app.exec_())
Y el error que me esta dando
Código Python:
Ver originalTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "C:/Users/Desktop/Python Test/toDelete.py", line 56, in <module>
producerThread.started.connect(producer.Start(vector))
TypeError: connect() slot argument should be a callable or a signal, not 'NoneType'