lukeanders70
lukeanders70

Reputation: 73

threading.Timer cannot call can't call it's own function in Python 3

I can't seem to get a function to call itself after a specific time interval using the Threading module as seen in this thread Run certain code every n seconds

when I run a copy of that code:

 import threading

 def printit():   
    threading.Timer(5.0, printit).start()   
    print("Hello, World!")

 printit()

It will print "Hello, World!" once (the original call function) and then run endlessly without printing anything new.

I know that the module is installed correctly, because when I run this

import threading 
def printit():   
    print ("Hello, World!")

threading.Timer(5.0, printit).start()

it will wait 5 seconds before printing "Hello, World!" just like it's supposed to. I think the problem lies in Python 3 because the linked Stack Overflow thread, as well as some others that I've looked at, were ll using python 2 and when I tried it on another machine with python 2 it worked. Any insight on why this may be happening or how to fix it would be greatly appreciated.

Upvotes: 0

Views: 419

Answers (1)

Rob Hansen
Rob Hansen

Reputation: 317

Running that code on Python 3.4.3 x64 on Windows 10, substituting print() for Martelli's original print, gives the expected behavior. I wish I could help you, but this doesn't appear reproducible.

Upvotes: 1

Related Questions