我有一个代码块,用于每 30 秒运行一段代码
def hello():
print "hello, world"
t = threading.Timer(30.0, hello)
t.start()
下面是一个类的方法,我真的想每 30 秒运行一次,但我遇到了问题。
def continousUpdate(self, contractId):
print 'hello, world new'
t = threading.Timer(30.0, self.continousUpdate, [self, contractId],{} )
t.start()
当我运行它时,我收到以下错误
pydev debugger: starting
hello, world new
Exception in thread Thread-4:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 552, in __bootstrap_inner
self.run()
File "C:\Python27\lib\threading.py", line 756, in run
self.function(*self.args, **self.kwargs)
TypeError: continousUpdate() takes exactly 2 arguments (3 given)
我也试过
def continousUpdate(self, contractId):
print 'hello, world new'
t = threading.Timer(30.0, self.continousUpdate(contractId))
t.start()
它以某种方式表现得好像它忽略了线程,并给出了递归限制错误