[python] Jak ladit QThreads z PySide nebo PyQt ?

Radek Holý radekholypublic na gmail.com
Pondělí Leden 14 01:05:33 CET 2013


ad PyCharm: http://youtrack.jetbrains.com/issue/PY-4299?query=e

-- 
Radek


2013/1/14 Radek Holý <radekholypublic 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.andrysek 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
>> Python na py.cz
>> http://www.py.cz/mailman/listinfo/python
>>
>
>
------------- další část ---------------
HTML příloha byla odstraněna...
URL: <http://www.py.cz/pipermail/python/attachments/20130114/52eb2ddf/attachment.html>


Další informace o konferenci Python