【发布时间】:2017-03-05 10:28:14
【问题描述】:
我想创建一个简单的计时器脚本来将它与我的电报机器人一起使用,但有些东西并没有像我想要的那样工作。代码如下:
#!/usr/bin/python
from threading import Timer
class Timer:
def __init__(self, router):
self.routes = [
("^/timer\s(?P<time>[^$]+)$", self.main),
]
def timer_end(self):
print 'Timer End'
def main(self, message, match):
Timer(5, self.timer_end, ()).start()
我总是收到这个错误:
TypeError: __init__() takes exactly 2 arguments (4 given)
如果有人可以提供帮助,那就太好了。 提前致谢!
【问题讨论】:
-
您导入 Timer,然后创建一个覆盖 Timer 的类。也许您应该只“导入线程”然后使用“threading.Timer”来区分两者?
-
糟糕,我自己也注意到了。非常感谢!
标签: python multithreading python-2.7 timer