.net

.net

 

Python 无限循环

 1 import threading
 2 import time
 3 
 4 
 5 class CountDownTimer(threading.Thread):
 6         def __init__(self, seconds, action):
 7             self.runTime = seconds
 8             self.action = action
 9             super(CountDownTimer, self).__init__()
10 
11         def run(self):
12             counter = self.runTime
13             for sec in range(self.runTime):
14                     print counter
15                     time.sleep(1.0)
16                     counter -= 1
17             print " Time's up"
18             self.action()
19 
20 
21 def dosomethine():
22     print "I'm ready"
23 
24     t = CountDownTimer(5, dosomethine)
25     t.start()
26 if __name__ == "__main__":
27 
28     t = CountDownTimer(5, dosomethine)
29     t.start()
View Code

 

posted on 2015-05-08 10:19  严杰  阅读(486)  评论(0编辑  收藏  举报

导航