我想在线程中运行一些计时器?但它显示错误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)
检查文档: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)