[英]Pyside: How can i know which thread emitted the signal “finished”?
I start some threads und would like to know which thread is finished: 我开始一些线程,但想知道哪个线程完成了:
...
...
def start_ten_threads(self):
self.workers = []
for i in range(0, 10):
self.workers.append(thread_worker(i, self))
...
...
for k in range(0, 10):
self.workers[k].finished.connect(lambda: self.print_finished("WorkerThread %d finished" % k))
self.workers[k].start()
@Slot(str)
def print_finished(self, str):
print(str)
I get for each thread the same number 9 (last value of k). 对于每个线程,我得到相同的数字9(k的最后一个值)。 Why?
为什么? Can i use parameters on this way with signal "finished"?
我可以通过信号“完成”以这种方式使用参数吗? I have already read some stuff about QSignalMapper.
我已经阅读了一些有关QSignalMapper的内容。 Is there another way here?
这里还有别的办法吗?
If i use self.sender() i get the point to the thread, but i don't know which thread number it is. 如果我使用self.sender(),我会指向该线程,但是我不知道它是哪个线程号。
For the lambda, try: 对于lambda,请尝试:
lambda k=k: self.print_finished("WorkerThread %d finished" % k)
^^^
With this syntax the value of k
at the time the lambda was created will be captured and used by the lambda. 使用这种语法,lambda将捕获并使用创建lambda时的
k
值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.