Threading.Timer(5, function) launch every 5 second

Viewed 9917

I'm having a hard hard time with Timer function from threading.

Basically, when my program starts, I want to log stats every x second.

So I thought I could do it with the Timer function (launch function every 5 second).

For now, I did :

from threading import Timer
def startLogger():
    while True:
        t = Timer(5, function)
        t.start()


def function():
    print("hey")

But it launch error, so I think it's not the good way to do it.

RuntimeError: can't start new thread

If someone can give me a clue, it would be appreciated!

2 Answers
Related