我想在线程中运行一些计时器,但显示错误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
答案 0 :(得分:4)
检查文档: https://docs.python.org/3/library/_thread.html
_thread.start_new_thread(函数,args [,kwargs])
启动一个新线程并返回其标识符。线程使用参数列表args(必须为元组)执行function函数。
因此,正确的呼叫如下:
_thread.start_new_thread(self.timer0.start, (100,))