0

I have a Python script that starts with one block of code that is supposed to keep everything on track. This code calls a function that prints some text and starts a Timer (from the threading module). The function called by the Timer also prints text, but that function never executes.

from threading import Timer

def func1():
    print "func1 successful"
    t = Timer(1, func2)
    t.start

def func2():
    print "func2 successful"

####program start####
print "test start"

func1()

The simplified version above exits after printing two lines of text. I tried adding an infinite loop at the bottom to make the program wait for the Timers, but then it merely failed to exit. Why does the second function not run?

1 Answer 1

3

Because you're not calling the start function.

from threading import Timer

def func1():
    print "func1 successful"
    t = Timer(1, func2)
    t.start()
    #      ^^

def func2():
    print "func2 successful"

####program start####
print "test start"

func1()

Should work now

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.