I'm trying to get some pyqt thread pools and process working but have run into a few issues and was wondering if anyone could help.
I've simplified the code down and have included it here.
When you run the following it seems the started()
method seems to get called twice for each process which isn't something I'd expect.
Also, I get the error QProcess: Destroyed
while process is still running.
Can anyone enlighten me as to why this occurs?
Running startDetached()
enables the code to work but because it doesn't return an object I lose all ability to use signals.
Any help would be much appreciated.
Thanks a lot
import sys
from PyQt4 import QtGui,QtCore
class Test(object):
def __init__(self):
self.elements = []
for i in range(5):
self.elements.append(Element(i))
def run(self):
pool = QtCore.QThreadPool()
pool.setMaxThreadCount(1)
for element in self.elements:
pool.start(element.worker)
pool.waitForDone()
class Worker(QtCore.QRunnable):
def __init__(self):
super(Worker, self).__init__()
class Element(object):
def __init__(self, number):
self.number = number
self.worker = Worker()
self.worker.run = self.run
def run(self):
process = QtCore.QProcess()
def started():
print "Started"
process.started.connect(started)
process.start('echo', 'hello')
app = QtGui.QApplication(sys.argv)
test = Test()
test.run()
widget = QtGui.QWidget()
widget.show()
app.exec_()