我在使用Timer线程功能时遇到了困难。
基本上,当我的程序启动时,我想每 x 秒记录一次统计信息。
所以我想我可以用这个Timer函数来做(每 5 秒启动一次函数)。
现在,我做了:
from threading import Timer
def startLogger():
while True:
t = Timer(5, function)
t.start()
def function():
print("hey")
Run Code Online (Sandbox Code Playgroud)
但它启动错误,所以我认为这不是一个好方法。
RuntimeError: can't start new thread
如果有人能给我一个线索,将不胜感激!