|
Class Timer (threading. Thread ):
"""
Very simple but useless timer.
"""
Def _ init _ (self, seconds ):
Self. runTime = seconds
Threading. Thread. _ init _ (self)
Def run (self ):
Time. sleep (self. runTime)
Print "Buzzzz !! Time's up! "
Class CountDownTimer (Timer ):
"""
A timer that can counts down the seconds.
"""
Def run (self ):
Counter = self. runTime
For sec in range (self. runTime ):
Print counter
Time. sleep (1.0)
Counter-= 1
Print "Done"
Class CountDownExec (CountDownTimer ):
"""
A timer that execute an action at the end of the timer run.
"""
Def _ init _ (self, seconds, action, args = []):
Self. args = args
Self. action = action
CountDownTimer. _ init _ (self, seconds)
Def run (self ):
CountDownTimer. run (self)
Self. action (self. args)
Def myAction (args = []):
Print "specify Ming my action with args :"
Print args
If _ name _ = "_ main __":
T = CountDownExec (3, myAction, ["hello", "world"])
T. start ()
|