[python] Jak ladit QThreads z PySide nebo PyQt ?
richard.andrysek na freenet.de
richard.andrysek na freenet.de
Pondělí Leden 14 08:42:04 CET 2013
Dne pondělí, 14. ledna 2013 1:05:33 UTC+1 Radek Holý napsal(a):
> ad PyCharm: http://youtrack.jetbrains.com/issue/PY-4299?query=e
>
> --
> Radek
>
>
>
>
>
>
> 2013/1/14 Radek Holý <radekho... na gmail.com>
>
>
>
> Zkusil jsem to v PyCharm (nikdy jsem tam ale debugger nezkousel) a na breakpointech v konstruktoru Workerů se mi to zastaví, ale na breakpointech v ``MyWorkerThread.run`` ne, takže PyCharm to asi také neumí...
>
>
>
> --
> Radek
>
>
>
>
>
>
>
>
>
> 2013/1/13 darkanry <richard.... na freenet.de>
>
>
> Stahl jsem si jednoduchy priklad pro praci s QThread. Priklad funguje bez problemu, tak jsem ho zacal upravovat. Bohuzel jsem zjistil, ze to v PyDev nejde ladit. Nevite nekdo jak na to? Kdyz to nejde s PyDev, jde to necim jinym?
>
>
>
>
>
> Priklad:
>
>
>
> #import pydevd
>
> #pydevd.connected = True
>
> #pydevd.settrace()
>
>
>
> from PySide import QtCore
>
>
>
> import time, sys
>
>
>
> class MyWorkerThread(QtCore.QThread):
>
> message = QtCore.Signal(str)
>
>
>
> def __init__(self, id, parent=None):
>
> super(MyWorkerThread, self).__init__(parent)
>
> self.id = id
>
>
>
> def run(self):
>
> for i in range(10):
>
> self.message.emit("%d: %d" % (self.id, i))
>
> time.sleep(0.2)
>
>
>
> class MainProgram():
>
> def __init__(self, parent=None):
>
> self.threads = []
>
>
>
> self.addWorker(MyWorkerThread(1))
>
> self.addWorker(MyWorkerThread(2))
>
>
>
> def addWorker(self, worker):
>
> worker.message.connect(self.printMessage, QtCore.Qt.QueuedConnection)
>
> # connect the finished signal to method so that we are notified
>
> worker.finished.connect(self.workersFinished)
>
> self.threads.append(worker)
>
>
>
> def startWorkers(self):
>
> for worker in self.threads:
>
> print worker.id
>
> worker.start()
>
> # no wait, no finished. you start the threads and leave.
>
>
>
> def workersFinished(self):
>
> if all(worker.isFinished() for worker in self.threads):
>
> # wait until all the threads finished
>
> QtCore.QCoreApplication.instance().quit()
>
>
>
> @QtCore.Slot(str)
>
> def printMessage(self, text):
>
> sys.stdout.write(text+'\n')
>
> sys.stdout.flush()
>
>
>
> if __name__ == '__main__':
>
>
>
> app = QtCore.QCoreApplication(sys.argv)
>
> m = MainProgram()
>
> m.startWorkers()
>
> sys.exit(app.exec_())
>
> _______________________________________________
>
> Python mailing list
>
> Pyt... na py.cz
>
> http://www.py.cz/mailman/listinfo/python
Presne to stejny jsem nasel pro PyDev. Doporuceni je pouzit namisto QThread Thread z pythonu. Tim ale zase nemam vyreseny signaly a sloty, nebo jde i to nejak?
Další informace o konferenci Python