<div dir="ltr"><div>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í...<br>
<br>-- <br></div>Radek<br><div><div><br><div class="gmail_extra"><br><br><div class="gmail_quote">2013/1/13 darkanry <span dir="ltr"><<a href="mailto:richard.andrysek@freenet.de" target="_blank">richard.andrysek@freenet.de</a>></span><br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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?<br>
<br>
Priklad:<br>
<br>
#import pydevd<br>
#pydevd.connected = True<br>
#pydevd.settrace()<br>
<br>
from PySide import QtCore<br>
<br>
import time, sys<br>
<br>
class MyWorkerThread(QtCore.QThread):<br>
message = QtCore.Signal(str)<br>
<br>
def __init__(self, id, parent=None):<br>
super(MyWorkerThread, self).__init__(parent)<br>
<a href="http://self.id" target="_blank">self.id</a> = id<br>
<br>
def run(self):<br>
for i in range(10):<br>
self.message.emit("%d: %d" % (<a href="http://self.id" target="_blank">self.id</a>, i))<br>
time.sleep(0.2)<br>
<br>
class MainProgram():<br>
def __init__(self, parent=None):<br>
self.threads = []<br>
<br>
self.addWorker(MyWorkerThread(1))<br>
self.addWorker(MyWorkerThread(2))<br>
<br>
def addWorker(self, worker):<br>
worker.message.connect(self.printMessage, QtCore.Qt.QueuedConnection)<br>
# connect the finished signal to method so that we are notified<br>
worker.finished.connect(self.workersFinished)<br>
self.threads.append(worker)<br>
<br>
def startWorkers(self):<br>
for worker in self.threads:<br>
print <a href="http://worker.id" target="_blank">worker.id</a><br>
worker.start()<br>
# no wait, no finished. you start the threads and leave.<br>
<br>
def workersFinished(self):<br>
if all(worker.isFinished() for worker in self.threads):<br>
# wait until all the threads finished<br>
QtCore.QCoreApplication.instance().quit()<br>
<br>
@QtCore.Slot(str)<br>
def printMessage(self, text):<br>
sys.stdout.write(text+'\n')<br>
sys.stdout.flush()<br>
<br>
if __name__ == '__main__':<br>
<br>
app = QtCore.QCoreApplication(sys.argv)<br>
m = MainProgram()<br>
m.startWorkers()<br>
sys.exit(app.exec_())<br>
_______________________________________________<br>
Python mailing list<br>
<a href="mailto:Python@py.cz">Python@py.cz</a><br>
<a href="http://www.py.cz/mailman/listinfo/python" target="_blank">http://www.py.cz/mailman/listinfo/python</a><br>
</blockquote></div><br></div></div></div></div>