0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.