小编Fra*_*lle的帖子

Threading.Timer(5, function) 每 5 秒启动一次

我在使用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

如果有人能给我一个线索,将不胜感激!

python timer python-multithreading

4
推荐指数
2
解决办法
7493
查看次数

标签 统计

python ×1

python-multithreading ×1

timer ×1