解决pythonTimer报错:Exception in thread Thread-1:Traceback most recent call last

解决pythonTimer报错:Exception in thread Thread-1:Traceback most recent call last

最近使用了python的Timer定时器功能,具体用法是:

Timer(interval, function, args=[], kwargs={
    
    }) 

interval: 指定的时间   
function: 要执行的方法   
args/kwargs: 方法的参数

然后我做了这样的应用:

t=Timer(timer_interval,clearTwoBlock())#定时函数

报错:

Exception in thread Thread-1:
Traceback (most recent call last):
File “D:\Python37\lib\threading.py”, line 917, in _bootstrap_inner
self.run()
File “D:\Python37\lib\threading.py”, line 1158, in run
self.function(*self.args, **self.kwargs)
TypeError: ‘NoneType’ object is not callable

出现该问题的原因是:

Timer的参数中function只写函数名,不要加括号,正确修改为:

t=Timer(timer_interval,clearTwoBlock)#定时函数

猜你喜欢

转载自blog.csdn.net/weixin_45386875/article/details/113828730
今日推荐