类型错误:* 后的 start() 参数必须是可迭代的,而不是 int

kev*_*701 1 python pyqt

我想在线程中运行一些计时器?但它显示错误TypeError: start() argument after * must be an iterable, not int?我该如何解决?

    while 1:
            try:
                _thread.start_new_thread(self.timer0.start,100)
                _thread.start_new_thread(self.timer1.start,150)
                _thread.start_new_thread(self.timer2.start,200)
                _thread.start_new_thread(self.timer3.start,250)
                _thread.start_new_thread(self.timer4.start,300)
                break
            except:
                print ("Error: unable to start thread")
            break
Run Code Online (Sandbox Code Playgroud)

Les*_*iak 8

检查文档:https : //docs.python.org/3/library/_thread.html

_thread.start_new_thread(function, args[, kwargs])

启动一个新线程并返回其标识符。线程使用参数列表 args(必须是元组)执行函数 function。

因此,正确的调用如下所示:

_thread.start_new_thread(self.timer0.start, (100,))
Run Code Online (Sandbox Code Playgroud)

  • 看来你对线程很着迷,你想一直使用它,QTimer是一个不是线程安全的QObject,所以你不能从另一个线程修改它,这就是为什么Qt告诉你不要修改QTimer来自与创建的线程不同的线程 (2认同)