Python timer countdown

后端 未结 7 810
南方客
南方客 2021-01-16 13:06

I want to know about timer in Python.

Suppose i have a code snippet something like:

def abc()
   print \'Hi\'  
   print \'Hello\'
   print \'Hai\'
<         


        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-16 14:09

    time.sleep is fine in this case but what if the abc() function takes half a second to execute? Or 5 minutes? In this case you should use a Timer object.

    from threading import Timer
    
    def abc():
        print 'Hi'  
        print 'Hello'
        print 'Hai'
    
    for i in xrange(3):
        Timer(i, abc).start()
    

提交回复
热议问题