Python Time Delays

前端 未结 2 1025
走了就别回头了
走了就别回头了 2020-11-27 06:07

I want to know how to call a function after a certain time. I have tried time.sleep() but this halts the whole script. I want the script to carry on, but after ???secs cal

2条回答
  •  忘掉有多难
    2020-11-27 06:21

    Have a look at threading.Timer. It runs your function in a new thread.

    from threading import Timer
    
    def hello():
        print "hello, world"
    
    t = Timer(30.0, hello)
    t.start() # after 30 seconds, "hello, world" will be printed
    

提交回复
热议问题