from threading import Timer
def startTimer():
t = Timer(10.0, foo, ['hello world', 'tell me more'] )
t.start()
print 'Timer function invoked'
print 'function exit'
def foo(msg, msg2):
print 'foo was executed'
print msg
print msg2
if __name__ == '__main__':
startTimer()
print 'end of program'
Run Code Online (Sandbox Code Playgroud)
我已将上述代码保存在文件(timer.py)中,然后在shell中键入python timer.py.但它一直等到foo()被执行.为什么会这样?你怎么称呼这种行为/执行方式?